diff --git a/PROMS/XYPlots/XYPlots.cs b/PROMS/XYPlots/XYPlots.cs index 248caf03..5700a00d 100644 --- a/PROMS/XYPlots/XYPlots.cs +++ b/PROMS/XYPlots/XYPlots.cs @@ -1,10 +1,10 @@ using System; using System.Collections; +using System.Collections.Generic; using System.IO; using System.Windows.Forms; using System.Text; using System.Drawing; -using C1.C1Pdf; using VG; namespace XYPlots @@ -14,71 +14,106 @@ namespace XYPlots /// public class XYPlot { - #region OldStuff -#if OldStuff - static long HP3_HPGL_COMPENSATEX = 1016L; /* OK, so you don't believe it */ - static long HP3_HPGL_COMPENSATEY = 1016L;/* OK, so you don't believe it */ - private long DotsToPlotterUnitsX(int x) + static string _MyFontFamily = "Letter Gothic Tall"; + public static string MyFontFamily { - long retval; - retval = (long)((1.0 * x * HP_FudgeX) / 300.0 + .5); - return (retval); + get { return _MyFontFamily; } + set { _MyFontFamily = value; } } - private long DotsToPlotterUnitsY(int y) + private static Color _BlackColor = Color.Red; + public static Color BlackColor { - long retval; - retval = (long)((1.0 * y * HP_FudgeY) / 300.0 + .5); - return (retval); + get { return VG.VG.BlackColor; } + set { VG.VG.BlackColor = value; } } - private long HP_FudgeX = HP3_HPGL_COMPENSATEX; - private long HP_FudgeY = HP3_HPGL_COMPENSATEY; - static long PRINTAPLOT_COMPENSATE = 1020L;/* but these resolve differently*/ - static int DASH = 2; - private void Graphics(int flag) + public float Width { - // if(graph_GraphicsStr[flag]) - // fprintf(stdprn,"%s",graph_GraphicsStr[flag]); + get { return 72 * (LeftMargin + RightMargin) + printerunits[0] * .05F; } + } + public float Height + { + get { return 72 * (TopMargin + BottomMargin) + printerunits[1] * .05F; } + } + public float PlotWidth + { + get { return (float) userunits[X]; } + } + public float PlotHeight + { + get { return (float) userunits[Y]; } } - private string GoodOldStringX; - private string GoodOldStringY; - - -#endif - #endregion - // private int ConvertToTwips = 1440; - private double ConvertToTwips = 4.8; static int MAX_XY_STACK = 8; /* this is max of CIE cursor/font stack */ static int DPI = 1440; //300; static int CWIDEDOTS = 120; //25; static int CHIGHDOTS = 240; //50; - static int STRAIGHT = 0; static int CURVE = 1; - static int X = 0; static int Y = 1; static int Dimensions = 2; static int USER = 0; static int PLOT = 1; - - static double PI=3.141592653; - static double Zero=0.0; - static double ANGLELIMIT=1.0; - + static double PI = 3.141592653; + static double Zero = 0.0; + static double ANGLELIMIT = 1.0; // !!!! NEED REAL SUPERSCRIPT ON/OFF TOKENS - static string []SuperScript = {"##","##"}; - static string []SubScript = {"~~","~~"}; - + static string[] SuperScript = { "##", "##" }; + static string[] SubScript = { "~~", "~~" }; FileStream XYPlotFile; - - private int []SavedX; + private int[] SavedX; private int[] SavedY; private int stack; - private int HPGLMode; - - - + /// + /// Set All Margins at once + /// + /// Left Margin in Inches. + /// Top Margin in Inches. + /// Right Margin in Inches. + /// Bottom Margin in Inches. + public void SetMargins(float leftMargin, float topMargin, float rightMargin, float bottomMargin) + { + _LeftMargin = leftMargin * 1440; + _TopMargin = topMargin * 1440; + _RightMargin = rightMargin * 1440; + _BottomMargin = bottomMargin * 1440; + } + private float _LeftMargin = 1440; + /// + /// Left Margin in Inches. + /// + public float LeftMargin + { + get { return _LeftMargin / 1440; } + set { _LeftMargin = value * 1440; } + } + private float _RightMargin = 720; + /// + /// Right Margin in Inches. + /// + public float RightMargin + { + get { return _RightMargin / 1440; } + set { _RightMargin = value * 1440; } + } + private float _TopMargin = 1440; + /// + /// Top Margin in Inches. + /// + public float TopMargin + { + get { return _TopMargin / 1440; } + set { _TopMargin = value * 1440; } + } + private float _BottomMargin = 1440; + /// + /// Bottom Margin in Inches. + /// + public float BottomMargin + { + get { return _BottomMargin / 1440; } + set { _BottomMargin = value * 1440; } + } public int LinesUsed; private string valuestring; private string powerstring; @@ -98,139 +133,110 @@ namespace XYPlots private int[] minor = new int[Dimensions]; private int[] spcminor = new int[Dimensions]; private string[] AxisTitles = new string[Dimensions]; - private int[] AxisLabel = new int[Dimensions];// = {1,1}; /* 1 for YES(default), 0 for NO*/ - private string LineBuff; + private int[] AxisLabel = new int[Dimensions];// 1 for YES(default), 0 for NO private int CurPenWidth, DrawDirection, LineFlag, LineDiv; private int EndFlag = 0; - public string Buff; //[4096],*BuffPtr; + public string Buff; private int BuffPtr = 0; - - private string _ThePDFFile; - - public string ThePDFFile - { - get { return _ThePDFFile; } - } - - //double (*f[2][2])(double); - private bool[,] doLOG10 = { { false, false }, { false, false } }; - - public struct point + public struct point { public int[] xyValue; //new int[Dimensions]; } - - public struct BoxList + public struct XyBox { public int Shadow; public string BoxText; public point BoxMinimum; public point BoxMaximum; - //BoxList *NextBox; }; - private ArrayList AllBoxes = new ArrayList(); - - public struct ActiveBoxList + public class XyBoxes : List { - public ArrayList BoxPtr; - //ActiveBoxList *NextActiveBox; - }; - private ArrayList AllActiveBoxes = new ArrayList(); - - public class PointList + } + private XyBoxes AllBoxes = new XyBoxes(); + private XyBoxes ActiveBoxes = new XyBoxes(); + public class DataPoint { private point m_APoint; - private double m_slope; /* slope of tangent to circle at this point */ public point APoint { - get{return m_APoint;} - set{m_APoint=value;} + get { return m_APoint; } + set { m_APoint = value; } } + private double m_slope; // slope of tangent to circle at this point public double slope { - get{return m_slope;} - set{m_slope=value;} + get { return m_slope; } + set { m_slope = value; } } - //PointList *NextPoint; }; -// public ArrayList PointListArray = new ArrayList(); - - public struct LineList + public class DataPoints : List + { + } + public struct PlotLine { public int PlotType; public int PlotDivisions; - // public PointList PlotPoint; - public ArrayList PlotPointsList; -// public LineList NextPlot; + public DataPoints PlotDataPoints; }; - private ArrayList AllPlots = new ArrayList(); - + private List AllPlots = new List(); private int YLandScape = 0; /* y axis title is horizontal */ private point YTitleOrigin; /* y axis title origin if vertical */ - - private double FixAngle(double a1) + private double FixAngle(double a1) { double retval; int sign; - if(a1 < 0) + if (a1 < 0) { - a1=-a1; - sign=-1; - } + a1 = -a1; + sign = -1; + } else - sign=1; - retval=sign*Math.Floor(0.5+a1); - return(retval); + sign = 1; + retval = sign * Math.Floor(0.5 + a1); + return retval; } - - private double dsquare(int val) + private double dsquare(int val) { double result; - result = (double)(val*val); - return( result ); + result = (double)(val * val); + return result; } - - private double FMin(double f1, double f2) + private double FMin(double f1, double f2) { - return((f1>=f2)?f2:f1); + return ((f1 >= f2) ? f2 : f1); } - - private double FMax(double f1, double f2) + private double FMax(double f1, double f2) { - return((f1>=f2)?f1:f2); + return ((f1 >= f2) ? f1 : f2); } - - private double atan_deg(double x) + private double atan_deg(double x) { - return( Math.Atan(x) * 180.0/ PI ); + return (Math.Atan(x) * 180.0 / PI); } - - private double cos_deg(double x) + private double cos_deg(double x) { - return( Math.Cos(x*PI/180.0) ); + return (Math.Cos(x * PI / 180.0)); } - - private double tan_deg(double x) + private double tan_deg(double x) { - return( Math.Tan(x*PI/180.0) ); + return (Math.Tan(x * PI / 180.0)); } - - private double sin_deg(double x) + private double sin_deg(double x) { - return( Math.Sin(x*PI/180.0) ); + return (Math.Sin(x * PI / 180.0)); } - - /* - ** the following function is pointed to by a function pointer - ** and is provided for compatibility with log10() function usage - */ - private double linear(double x) + /// + /// the following function is pointed to by a function pointer + /// and is provided for compatibility with log10() function usage + /// + /// + /// + private double linear(double x) { - return(x); + return x; } - - private bool isWhiteSpace(char cptr) + private bool isWhiteSpace(char cptr) { bool rtnval = false; if (!cptr.Equals(null)) @@ -239,372 +245,308 @@ namespace XYPlots rtnval = (idx > -1); } return rtnval; - // return((c) ? strchr("\t\n\r\f ",c):NULL); } - - // int NextPiece() - private string NextPiece() + private string NextPiece() { string rtnval; - // char *ptr; int ptr; -// int buflen = Buff.Length; - while(BuffPtr >= 0 && Buff[BuffPtr] != 0 && isWhiteSpace(Buff[BuffPtr]))BuffPtr++; -// while(BuffPtr < buflen && Buff[BuffPtr] != 0 && isWhiteSpace(Buff[BuffPtr]))BuffPtr++; - ptr=BuffPtr; - while(BuffPtr >= 0 && Buff[BuffPtr] != 0 && !isWhiteSpace(Buff[BuffPtr]))BuffPtr++; -// while(BuffPtr < buflen && Buff[BuffPtr] != 0 && !isWhiteSpace(Buff[BuffPtr]))BuffPtr++; - if ( EndOfCommand() ) EndFlag=1; - - rtnval = Buff.Substring(ptr,BuffPtr-ptr); + while (BuffPtr >= 0 && Buff[BuffPtr] != 0 && isWhiteSpace(Buff[BuffPtr])) BuffPtr++; + ptr = BuffPtr; + while (BuffPtr >= 0 && Buff[BuffPtr] != 0 && !isWhiteSpace(Buff[BuffPtr])) BuffPtr++; + if (EndOfCommand()) EndFlag = 1; + rtnval = Buff.Substring(ptr, BuffPtr - ptr); BuffPtr++; return rtnval; } - - private bool EndOfCommand() + private bool EndOfCommand() { int tmpPtr = BuffPtr; -// if (BuffPtr >= Buff.Length) -// return true; while (!Buff[tmpPtr].Equals('\0') && Buff[tmpPtr].Equals(' ')) tmpPtr++; - if (!Buff[tmpPtr].Equals('\0') && !isWhiteSpace(Buff[tmpPtr])) + if (!Buff[tmpPtr].Equals('\0') && !isWhiteSpace(Buff[tmpPtr])) return false; else if (Buff[tmpPtr] == '\r' || Buff[tmpPtr] == '\n' || Buff[tmpPtr] == '\0') return true; else return false; } - - private bool LoadBuff(string FileName) + private bool LoadBuff(string FileName) { if (!File.Exists(FileName)) { // File does not exist, show error message - MessageBox.Show(String.Format("X/Y Plot File {0} Does Not Exist",FileName),"Error Opening X/Y Plot File"); + MessageBox.Show(String.Format("X/Y Plot File {0} Does Not Exist", FileName), "Error Opening X/Y Plot File"); return false; } - // Open the X/Y Plot file - try + try { XYPlotFile = File.OpenRead(FileName); } catch (Exception e) { // cannot open the x/y plot file - MessageBox.Show(e.Message,String.Format("Error Opening {0} for Reading",FileName)); + MessageBox.Show(e.Message, String.Format("Error Opening {0} for Reading", FileName)); return false; } - int blen = (int)XYPlotFile.Length; int bread = 0; - // initialize a byte array to read into - byte []bbuf = new byte[blen+1]; - for (int i=0; i\r\n<",ptr)) > 0) + while ((ptr = Buff.IndexOf(">\r\n<", ptr)) > 0) { // blank out ">" - Buff = Buff.Remove(ptr,1); - Buff = Buff.Insert(ptr," "); + Buff = Buff.Remove(ptr, 1); + Buff = Buff.Insert(ptr, " "); // remove "<" - Buff = Buff.Remove(ptr+3,1); + Buff = Buff.Remove(ptr + 3, 1); // if command on next line is blank, // combine with the previous line - if (Buff[ptr+3] == ' ') - Buff = Buff.Remove(ptr,3); + if (Buff[ptr + 3] == ' ') + Buff = Buff.Remove(ptr, 3); } ptr = Buff.Length - 5; // back up past >>\r\n - - // if (Buff.EndsWith(">>\r\n")) if (Buff.IndexOf(">>\r\n", ptr) > 0) { Buff = Buff.Remove(ptr, 2); Buff = Buff.Insert(ptr, " "); - // Buff[ptr] = ' '; - // Buff[ptr+1] = ' '; } else if (Buff.EndsWith(">>")) // doesn't end with return chars... Buff = Buff.Substring(0, Buff.Length - 2) + " \r\n\0x00"; // needs to end with null } - - private void CloseGraph() + private void CloseGraph() { /* Send back number of lines used assuming 6 lines per inch */ - if( LinesUsed==0 ) - LinesUsed=(int)(1.5 * CHIGHDOTS); /* adjust for x axis tics */ + if (LinesUsed == 0) + LinesUsed = (int)(1.5 * CHIGHDOTS); /* adjust for x axis tics */ LinesUsed += printerunits[Y]; - LinesUsed = LinesUsed/CHIGHDOTS; + LinesUsed = LinesUsed / CHIGHDOTS; } - - private void GetScaleInfo() + private void GetScaleInfo() { - GridOnFlag=getint(); - userunits[X]=getdouble(); - userunits[Y]=getdouble(); -// f[USER][X]=linear; /* f is a function pointer */ -// f[USER][Y]=linear; /* linear is a function */ - printerunits[X]=(int)(DPI*userunits[X]); - printerunits[Y]=(int)(DPI*userunits[Y]); - minimum[X]=getdouble(); - maximum[X]=getdouble(); - minimum[Y]=getdouble(); - maximum[Y]=getdouble(); - type[X]=getchr(); - type[Y]=getchr(); - if(EndFlag == 0) delta[X]=getdouble(); - if(EndFlag == 0) delta[Y]=getdouble(); - if(EndFlag == 0) spcminor[X]=getint(); - if(EndFlag == 0) spcminor[Y]=getint(); - Offset[USER,X]=0; - Offset[USER,Y]=0; - Scale[USER,X]=DPI; - Scale[USER,Y]=DPI; - + GridOnFlag = getint(); + userunits[X] = getdouble(); + userunits[Y] = getdouble(); + printerunits[X] = (int)(DPI * userunits[X]); + printerunits[Y] = (int)(DPI * userunits[Y]); + minimum[X] = getdouble(); + maximum[X] = getdouble(); + minimum[Y] = getdouble(); + maximum[Y] = getdouble(); + type[X] = getchr(); + type[Y] = getchr(); + if (EndFlag == 0) delta[X] = getdouble(); + if (EndFlag == 0) delta[Y] = getdouble(); + if (EndFlag == 0) spcminor[X] = getint(); + if (EndFlag == 0) spcminor[Y] = getint(); + Offset[USER, X] = 0; + Offset[USER, Y] = 0; + Scale[USER, X] = DPI; + Scale[USER, Y] = DPI; /* in the following if blocks, the array variable f is a function pointer which is set to either the function linear or log10. */ /* X-axis function generation and scaling */ - if(type[X] != 'L') - { - // Linear - doLOG10[PLOT,X]=false; - LinearScale(X); - Scale[PLOT,X] = printerunits[X] / (maximum[X]- minimum[X]); - Offset[PLOT,X] =- Scale[PLOT,X] * minimum[X]; - } - else - { - // Log10 - doLOG10[PLOT,X]=true; - LogScale(X); - Scale[PLOT,X] = printerunits[X] / - (Math.Log10(maximum[X])- Math.Log10(minimum[X])); - Offset[PLOT,X] =- Scale[PLOT,X] * Math.Log10(minimum[X]); - } - - /* Y-axis function generation and scaling */ - if(type[Y] != 'L') + if (type[X] != 'L') { // Linear - doLOG10[PLOT,Y]=false; - LinearScale(Y); - Scale[PLOT,Y]=printerunits[Y]/ (maximum[Y] - minimum[Y]); - Offset[PLOT,Y] =- Scale[PLOT,Y] * minimum[Y]; + doLOG10[PLOT, X] = false; + LinearScale(X); + Scale[PLOT, X] = printerunits[X] / (maximum[X] - minimum[X]); + Offset[PLOT, X] = -Scale[PLOT, X] * minimum[X]; } - else - { + else + { // Log10 - doLOG10[PLOT,Y]=true; - LogScale(Y); - Scale[PLOT,Y]=printerunits[Y]/ + doLOG10[PLOT, X] = true; + LogScale(X); + Scale[PLOT, X] = printerunits[X] / + (Math.Log10(maximum[X]) - Math.Log10(minimum[X])); + Offset[PLOT, X] = -Scale[PLOT, X] * Math.Log10(minimum[X]); + } + /* Y-axis function generation and scaling */ + if (type[Y] != 'L') + { + // Linear + doLOG10[PLOT, Y] = false; + LinearScale(Y); + Scale[PLOT, Y] = printerunits[Y] / (maximum[Y] - minimum[Y]); + Offset[PLOT, Y] = -Scale[PLOT, Y] * minimum[Y]; + } + else + { + // Log10 + doLOG10[PLOT, Y] = true; + LogScale(Y); + Scale[PLOT, Y] = printerunits[Y] / (Math.Log10(maximum[Y]) - Math.Log10(minimum[Y])); - Offset[PLOT,Y] =- Scale[PLOT,Y] * Math.Log10(minimum[Y]); + Offset[PLOT, Y] = -Scale[PLOT, Y] * Math.Log10(minimum[Y]); } } - - - private void GetAxisTitle(int flag) + private void GetAxisTitle(int flag) { - AxisTitles[flag]=GetString(); + AxisTitles[flag] = GetString(); } - private string stripSuperSub(string instr) { StringBuilder sb = new StringBuilder(instr); - sb.Replace(SuperScript[0],""); - sb.Replace(SuperScript[1],""); - sb.Replace(SubScript[0],""); - sb.Replace(SubScript[1],""); + sb.Replace(SuperScript[0], ""); + sb.Replace(SuperScript[1], ""); + sb.Replace(SubScript[0], ""); + sb.Replace(SubScript[1], ""); return sb.ToString(); } - - private point DetermineBoxMax(BoxList boxptr) + private point DetermineBoxMax(XyBox boxptr) { - point newval = new point(); newval.xyValue = new int[Dimensions]; string tmp; int pos = 0, prevPos = 0; int nl = 0, xmax = 0, ilen = 0; tmp = stripSuperSub(boxptr.BoxText); - while ((pos = tmp.IndexOf('\n',pos)) > -1) + tmp = tmp.Replace("\r\n", "\n"); + while ((pos = tmp.IndexOf('\n', pos)) > -1) { - ilen = pos - prevPos; // -1; this will fix an arythmatic bug - xmax = Math.Max(xmax,ilen); - prevPos = pos; + ilen = pos - prevPos; + xmax = Math.Max(xmax, ilen); + // OLD: prevPos = pos; + prevPos = pos + 1; pos++; nl++; } - ilen = tmp.Substring(prevPos+1).Length; - xmax = Math.Max(xmax,ilen) + 2; -// nl += 2; - newval.xyValue[X] = boxptr.BoxMinimum.xyValue[X]+(xmax*CWIDEDOTS); - newval.xyValue[Y] = boxptr.BoxMinimum.xyValue[Y]-(nl*CHIGHDOTS)-(int)(30 * ConvertToTwips); -// newval.xyValue[Y] = boxptr.BoxMinimum.xyValue[Y]+(nl*CHIGHDOTS)-(int)(30 * ConvertToTwips); -// boxptr.BoxMaximum = newval; + // OLD: ilen = tmp.Substring(prevPos + 1).Length; + ilen = tmp.Length - prevPos; // tmp.Substring(prevPos).Length; + xmax = Math.Max(xmax, ilen) + 2; + newval.xyValue[X] = boxptr.BoxMinimum.xyValue[X] + (xmax * CWIDEDOTS); + // OLD: newval.xyValue[Y] = boxptr.BoxMinimum.xyValue[Y] - (nl * CHIGHDOTS) - (int)(30 * ConvertToTwips); + newval.xyValue[Y] = boxptr.BoxMinimum.xyValue[Y] - (nl * CHIGHDOTS) - (int)(19 * ConvertToTwips); return newval; } - - - private void GetBoxParameters() + private void GetBoxParameters() { - BoxList NewBox = new BoxList(); -// point Origin = new point(); -// Origin.xyValue = new int[Dimensions]; + XyBox NewBox = new XyBox(); point Origin; Origin = GetPair(USER); string str = GetString(); @@ -613,7 +555,6 @@ namespace XYPlots NewBox.Shadow = ShadowFlag; ShadowFlag = 0; NewBox.BoxMaximum = DetermineBoxMax(NewBox); - // jsj point minPoint = new point(); minPoint.xyValue = new int[Dimensions]; point maxPoint = new point(); @@ -622,53 +563,37 @@ namespace XYPlots minPoint.xyValue[Y] = NewBox.BoxMaximum.xyValue[Y]; maxPoint.xyValue[X] = NewBox.BoxMaximum.xyValue[X]; maxPoint.xyValue[Y] = Origin.xyValue[Y]; - NewBox.BoxMinimum = minPoint; NewBox.BoxMaximum = maxPoint; - //jsj AllBoxes.Add(NewBox); } - - private void GetLineParameters() + private void GetLineParameters() { - // PointList NewPlotData; - // int curptr, prevptr; - ArrayList PointListArray = new ArrayList(); + DataPoints dataPoints = new DataPoints(); int pointcount; pointcount = EndFlag = 0; while (EndFlag == 0) { - PointList pl = new PointList(); + DataPoint pl = new DataPoint(); pl.APoint = new point(); - //pl.APoint.xyValue = new int[Dimensions]; pl.APoint = GetPair(PLOT); pointcount++; - PointListArray.Add(pl); + dataPoints.Add(pl); } if (LineFlag == CURVE && pointcount > 2) - CalculateSlopes(PointListArray); + CalculateSlopes(dataPoints); else LineFlag = STRAIGHT; #if DEBUG - ShowPoints(PointListArray); + ShowPoints(dataPoints); #endif - AddAPlot(PointListArray); + AddAPlot(dataPoints); } -#if DEBUG - private void ShowPoints(ArrayList al) - { - foreach(PointList pl in al) - { - Console.WriteLine("x={0},y={1},slope={2}",pl.APoint.xyValue[0],pl.APoint.xyValue[1], pl.slope); - } - } -#endif - private double FindSlope(point first, point last) + private double FindSlope(point first, point last) { double dx, dy, result; dx = last.xyValue[X] - first.xyValue[X]; dy = (last.xyValue[Y] - first.xyValue[Y]); -// dy = first.xyValue[Y] - last.xyValue[Y]; if (dx == 0.0) { if (dy > 0) @@ -677,85 +602,89 @@ namespace XYPlots result = Convert.ToDouble("-1.E99"); } else - result = dy/dx; + result = dy / dx; return result; } - - private double FindEndSlope(point first, point last, double s1) + private double FindEndSlope(point first, point last, double s1) { double result; - result = 2.0 * FindSlope (first,last) - s1; + result = 2.0 * FindSlope(first, last) - s1; if (result * s1 < 0.0) result = 0.0; return result; } - - private void CalculateSlopes(ArrayList PlAry) + private void CalculateSlopes(DataPoints dataPoints) { - PointList thispt, prevpt, firstpt; + DataPoint thispt, prevpt, firstpt; long yval, y1, y3; int PlAryIdx = 0; - int PlAryNumItems = PlAry.Count; - prevpt = (PointList) PlAry[PlAryIdx]; + int PlAryNumItems = dataPoints.Count; + prevpt = dataPoints[PlAryIdx]; PlAryIdx++; - thispt = (PointList) PlAry[PlAryIdx]; - while (PlAryIdx + 1 < PlAry.Count) + thispt = dataPoints[PlAryIdx]; + while (PlAryIdx + 1 < dataPoints.Count) { thispt.slope = Zero; yval = thispt.APoint.xyValue[Y]; y1 = prevpt.APoint.xyValue[Y]; - y3 = ((PointList)PlAry[PlAryIdx +1]).APoint.xyValue[Y]; - if ((yval-y1)*(y3-yval) > 0) -// if ((yval-y1)*(y3-yval) < 0) // jsj - thispt.slope = FindSlope(prevpt.APoint,((PointList)PlAry[PlAryIdx +1]).APoint); + y3 = dataPoints[PlAryIdx + 1].APoint.xyValue[Y]; + if ((yval - y1) * (y3 - yval) > 0) + thispt.slope = FindSlope(prevpt.APoint, dataPoints[PlAryIdx + 1].APoint); prevpt = thispt; PlAryIdx++; - thispt = (PointList)PlAry[PlAryIdx]; + thispt = dataPoints[PlAryIdx]; } - firstpt = (PointList)PlAry[0]; - firstpt.slope = FindEndSlope(firstpt.APoint,((PointList)PlAry[1]).APoint,((PointList)PlAry[1]).slope); - - thispt.slope = FindEndSlope(thispt.APoint,prevpt.APoint,prevpt.slope); + firstpt = dataPoints[0]; + firstpt.slope = FindEndSlope(firstpt.APoint, dataPoints[1].APoint, dataPoints[1].slope); + thispt.slope = FindEndSlope(thispt.APoint, prevpt.APoint, prevpt.slope); } - - private void AddAPlot(ArrayList ptr) + private void AddAPlot(DataPoints ptr) { - LineList NewLine = new LineList(); + PlotLine NewLine = new PlotLine(); NewLine.PlotType = LineFlag; NewLine.PlotDivisions = LineDiv; - NewLine.PlotPointsList = ptr; - AllPlots.Insert(0,NewLine); + NewLine.PlotDataPoints = ptr; + AllPlots.Insert(0, NewLine); } - - private void GenerateGrid(VG.Page pg, C1PdfDocument pdf) + private void GenerateGrid(VG.Page pg, IVGOutput vgOutput) { - AllActiveBoxes.Clear(); - SetPenDiameter(5); - Position[X]= 0; - Position[Y]= 0; // printerunits[Y]; + ActiveBoxes.Clear(); + Position[X] = 0; + Position[Y] = 0; // printerunits[Y]; SavePosition(); - BoxRelative(printerunits[X],printerunits[Y],CurPenWidth,pg,pdf); - if(GridOnFlag == 0) Visible=0; - DrawDirection=Y; - DoGrid(X,pg,pdf); - DrawDirection=X; - DoGrid(Y,pg,pdf); - Visible=1; + if (GridOnFlag == 0) Visible = 0; + //if (vgOutput is VGOut_Graphics) + //{ + DoGrid(X, pg, vgOutput, 1); + DoGrid(Y, pg, vgOutput, 1); + DoGrid(X, pg, vgOutput, 2); + DoGrid(Y, pg, vgOutput, 2); + DoGrid(X, pg, vgOutput, 3); + DoGrid(Y, pg, vgOutput, 3); + //} + //else if (vgOutput is VGOut_C1PDF) + //{ + // DrawDirection = Y; + // DoGrid(X, pg, vgOutput); + // DrawDirection = X; + // DoGrid(Y, pg, vgOutput); + //} + Visible = 1; RecallPosition(); + // Draw outline last to overlap any grid lines. + SetPenDiameter(5); + BoxRelative(printerunits[X], printerunits[Y], CurPenWidth, pg, vgOutput); } - - private void DoGrid(int flag, VG.Page pg, C1PdfDocument pdf) + private void DoGrid(int flag, VG.Page pg, IVGOutput vgOutput) { - if( type[flag] != 'L' ) - DoLinearGrid(flag,pg,pdf); + if (type[flag] != 'L') + DoLinearGrid(flag, pg, vgOutput); else - DoLogGrid(flag,pg,pdf); + DoLogGrid(flag, pg, vgOutput); } - - private void DoLinearGrid(int flag, VG.Page pg, C1PdfDocument pdf) + private void DoLinearGrid(int flag, VG.Page pg, IVGOutput vgOutput) { - int i,n,ns,subminor; -// int i,n,ns,x1,x2,y1,y2,subminor; + int i, n, ns, subminor; int ptval; n = (int)(0.5 + (maximum[flag] - minimum[flag]) / delta[flag]); ns = n * minor[flag]; @@ -763,64 +692,91 @@ namespace XYPlots subminor = minor[flag]; else subminor = minor[flag] / 2; - for(i=0; i <= ns; i++) + for (i = 0; i <= ns; i++) { - SetPenDiameter((((i % minor[flag])!=0) ? (((i % subminor)!=0) ? 1 : 2) : 3)); + SetPenDiameter((((i % minor[flag]) != 0) ? (((i % subminor) != 0) ? 1 : 2) : 3)); ptval = ((int)printerunits[flag]) * i / ns; - if (flag ==Y) + if (flag == Y) ptval = printerunits[Y] - ptval; - MoveAbsolute(((flag == X)? ptval : 0),((flag == Y)? ptval : 0)); -// MoveAbsolute(((flag == X)? ptval : 0),((flag == Y)? ptval : printerunits[Y])); - if(i % minor[flag] == 0) - WriteValue(flag,minimum[flag] + i * delta[flag] / minor[flag],false,pg,pdf); -// DrawGridLine(!flag,ptval); - DrawGridLine((flag==0)?1:0,ptval,pg,pdf); + MoveAbsolute(((flag == X) ? ptval : 0), ((flag == Y) ? ptval : 0)); + if (i % minor[flag] == 0) + WriteValue(flag, minimum[flag] + i * delta[flag] / minor[flag], false, pg, vgOutput); + DrawGridLine((flag == 0) ? 1 : 0, ptval, pg, vgOutput); } } - - private void DoLogGrid(int flag, VG.Page pg, C1PdfDocument pdf) + private void DoGrid(int flag, VG.Page pg, IVGOutput vgOutput, int gridPen) + { + DrawDirection = 1 - flag; + if (type[flag] != 'L') + DoLinearGrid(flag, pg, vgOutput, gridPen); + else + if (gridPen == 3) DoLogGrid(flag, pg, vgOutput); + } + private void DoLinearGrid(int flag, VG.Page pg, IVGOutput vgOutput, int gridPen) + { + int i, n, ns, subminor; + int ptval; + n = (int)(0.5 + (maximum[flag] - minimum[flag]) / delta[flag]); + ns = n * minor[flag]; + if ((minor[flag] % 2) != 0) + subminor = minor[flag]; + else + subminor = minor[flag] / 2; + for (i = 0; i <= ns; i++) + { + int pd = (((i % minor[flag]) != 0) ? (((i % subminor) != 0) ? 1 : 2) : 3); + if (pd == gridPen) + { + SetPenDiameter(pd); + ptval = ((int)printerunits[flag]) * i / ns; + if (flag == Y) + ptval = printerunits[Y] - ptval; + MoveAbsolute(((flag == X) ? ptval : 0), ((flag == Y) ? ptval : 0)); + if (i % minor[flag] == 0) + WriteValue(flag, minimum[flag] + i * delta[flag] / minor[flag], false, pg, vgOutput); + DrawGridLine((flag == 0) ? 1 : 0, ptval, pg, vgOutput); + } + } + } + private void DoLogGrid(int flag, VG.Page pg, IVGOutput vgOutput) { double showval; - int gs,ge,gd; - int i,ptval; -// int i,x1,x2,y1,y2,ptval; - showval =minimum[flag]; - for (i=0; i < cycles[flag]; i++) + int gs, ge, gd; + int i, ptval; + showval = minimum[flag]; + for (i = 0; i < cycles[flag]; i++) { gs = gd = 100; ge = 1000; - ptval=((int)printerunits[flag]) * i / cycles[flag]; - if (flag ==Y) + ptval = ((int)printerunits[flag]) * i / cycles[flag]; + if (flag == Y) ptval = printerunits[Y] - ptval; //jj - MoveAbsolute(((flag == X)? ptval : 0),((flag == Y)? ptval : 0)); + MoveAbsolute(((flag == X) ? ptval : 0), ((flag == Y) ? ptval : 0)); SetPenDiameter(3); - WriteValue(flag,showval,false,pg,pdf); - GenGrid(flag,gs,ge,gd,onecycle[flag],2,i * onecycle[flag],pg,pdf); + WriteValue(flag, showval, false, pg, vgOutput); + GenGrid(flag, gs, ge, gd, onecycle[flag], 2, i * onecycle[flag], pg, vgOutput); showval *= 10.0; } - ptval=((int)printerunits[flag]) * i / cycles[flag]; - if (flag ==Y) + ptval = ((int)printerunits[flag]) * i / cycles[flag]; + if (flag == Y) ptval = printerunits[Y] - ptval; //jj - MoveAbsolute(((flag == X)? ptval : 0),((flag == Y)? ptval : 0)); + MoveAbsolute(((flag == X) ? ptval : 0), ((flag == Y) ? ptval : 0)); SetPenDiameter(3); - WriteValue(flag,showval,false,pg,pdf); + WriteValue(flag, showval, false, pg, vgOutput); } - - private void WriteValue(int flag, double val, bool SubLogValue, VG.Page pg, C1PdfDocument pdf) + private void WriteValue(int flag, double val, bool SubLogValue, VG.Page pg, IVGOutput vgOutput) { int size; - size=GenNumberString(val); + size = GenNumberString(val); SavePosition(); - if (flag == X) + if (flag == X) { - MoveRelative(0,-printerunits[Y]); -// DrawGridRelative(0,30,pg,pdf); -// DrawGridRelative(0,(int)(-30 * ConvertToTwips) - printerunits[Y],pg,pdf); + MoveRelative(0, -printerunits[Y]); if (!SubLogValue) - DrawGridRelative(0,(int)(-30 * ConvertToTwips),pg,pdf); - // MoveRelative((int)((-150 * size / (int)FontPitch) * ConvertToTwips), (int)(60 * ConvertToTwips)); - MoveRelative((int)((-130 * size / (int)FontPitch) * ConvertToTwips), (int)(-60 * ConvertToTwips)); - if ((AxisLabel[0])!=0) + DrawGridRelative(0, (int)(-30 * ConvertToTwips), pg, vgOutput); + // OLD: MoveRelative((int)((-130 * size / (int)FontPitch) * ConvertToTwips), (int)(-60 * ConvertToTwips)); + MoveRelative((int)((2 - 130 * size / (int)FontPitch) * ConvertToTwips), (int)(-62 * ConvertToTwips)); + if ((AxisLabel[0]) != 0) { if (SubLogValue) { @@ -829,19 +785,18 @@ namespace XYPlots sb.Append(valuestring); sb.Append(SuperScript[1]); valuestring = sb.ToString(); - MoveRelative(30,30); + MoveRelative(30, 30); } - GraphText(valuestring,pg,pdf); + GraphText(valuestring, pg, vgOutput); } - } - else + } + else { -// DrawGridRelative(-30,0,pg,pdf); if (!SubLogValue) - DrawGridRelative((int)(-30 * ConvertToTwips),0,pg,pdf); -// MoveRelative((int)(-(15 + 300 * size / (int)FontPitch) * ConvertToTwips), (int) (15 * ConvertToTwips)); - MoveRelative((int)(-(15 + 300 * size / (int)FontPitch) * ConvertToTwips), (int) (-15 * ConvertToTwips)); - if((AxisLabel[1])!=0) + DrawGridRelative((int)(-30 * ConvertToTwips), 0, pg, vgOutput); + // OLD: MoveRelative((int)(-(15 + 300 * size / (int)FontPitch) * ConvertToTwips), (int)(-15 * ConvertToTwips)); + MoveRelative((int)(-(14 + 250 * size / (int)FontPitch) * ConvertToTwips), (int)(-16 * ConvertToTwips)); + if ((AxisLabel[1]) != 0) { if (SubLogValue) { @@ -850,1231 +805,909 @@ namespace XYPlots sb.Append(valuestring); sb.Append(SuperScript[1]); valuestring = sb.ToString(); - MoveRelative(90,-90); //jj + MoveRelative(90, -90); //jj } - GraphText(valuestring,pg,pdf); + GraphText(valuestring, pg, vgOutput); } } RecallPosition(); } - - private int GenNumberString(double x) + private int GenNumberString(double x) { - int power,size,sign; + int power, size, sign; double mantissa; - if(x==0.0) return(savenumber(x)); - if(x<0.0) + if (x == 0.0) return (savenumber(x)); + if (x < 0.0) { - x=-x; - sign=1; - } + x = -x; + sign = 1; + } else - sign=0; - mantissa=Math.Log10(x); - power=0; - while(mantissa < 0.999) + sign = 0; + mantissa = Math.Log10(x); + power = 0; + while (mantissa < 0.999) { power--; mantissa++; } - while(mantissa >= 0.999) + while (mantissa >= 0.999) { power++; mantissa--; } - if(mantissa < 0) - mantissa=0; - if(power > -5 && power < 5) - size=savenumber(x); - else + if (mantissa < 0) + mantissa = 0; + if (power > -5 && power < 5) + size = savenumber(x); + else { - size = savenumber(Math.Pow(10.0,mantissa)); + size = savenumber(Math.Pow(10.0, mantissa)); size += addpower(power); if (valuestring.StartsWith("1x")) { size -= 2; - valuestring = valuestring.Remove(0,2); + valuestring = valuestring.Remove(0, 2); } } - if(sign != 0) + if (sign != 0) { valuestring = "-" + valuestring; size++; } - return(size); + return (size); } - - private int savenumber(double x) + private int savenumber(double x) { - // valuestring = x.ToString("F"); valuestring = x.ToString("G"); return valuestring.Length; } - - private int addpower(int i) + private int addpower(int i) { int tlen; - powerstring = string.Format("x10{0}{1}{2}",SuperScript[1],i.ToString(),SuperScript[2]); + powerstring = string.Format("x10{0}{1}{2}", SuperScript[1], i.ToString(), SuperScript[2]); valuestring = valuestring + powerstring; - tlen=SuperScript[0].Length + SuperScript[1].Length; - return(powerstring.Length - tlen); + tlen = SuperScript[0].Length + SuperScript[1].Length; + return (powerstring.Length - tlen); } - - private void DoAxisTitles(VG.Page pg, C1PdfDocument pdf) + private void DoAxisTitles(VG.Page pg, IVGOutput vgOutput) { - int len,frommargin; -// int axismax,axismin; + int len, frommargin; string str; - // string []newstr = {"",""}; - SavePosition(); - if((AxisTitles[X] != null) && (len=AxisTitles[X].Length) > 0 ) + if ((AxisTitles[X] != null) && (len = AxisTitles[X].Length) > 0) { - frommargin=(int)((0.5 * (printerunits[X])) - (0.5 * (len * CWIDEDOTS))); -// MoveAbsolute(frommargin, -3 * CHIGHDOTS); + frommargin = (int)((0.5 * (printerunits[X])) - (0.47 * (len * CWIDEDOTS))); + // OLD: frommargin = (int)((0.5 * (printerunits[X])) - (0.5 * (len * CWIDEDOTS))); MoveAbsolute(frommargin, (3 * CHIGHDOTS) + printerunits[Y]); - PrintText(AxisTitles[X],pg,pdf); + PrintText(AxisTitles[X], pg, vgOutput); LinesUsed += (3 * CHIGHDOTS); - // Zfree(&AxisTitles[X]); AxisTitles[X] = null; } - if((AxisTitles[Y] != null) && (len=AxisTitles[Y].Length) > 0) + if ((AxisTitles[Y] != null) && (len = AxisTitles[Y].Length) > 0) { - if(YLandScape > 0) + if (YLandScape > 0) { int strIdx = 0; - // newstr[1] = null; MoveTo(YTitleOrigin); str = AxisTitles[Y]; - while(strIdx < str.Length) + while (strIdx < str.Length) { - // newstr[0] = *str; - // PrintText( newstr ); - PrintText (str[strIdx].ToString(),pg,pdf); - MoveRelative(0,-CHIGHDOTS); - strIdx ++; - // str++; + PrintText(str[strIdx].ToString(), pg, vgOutput); + MoveRelative(0, -CHIGHDOTS); + strIdx++; } - } - else - { -// MoveAbsolute(-3 * CWIDEDOTS, printerunits[Y] + CHIGHDOTS); - MoveAbsolute(-3 * CWIDEDOTS, - CHIGHDOTS); - PrintText(AxisTitles[Y],pg,pdf); } - // Zfree(&AxisTitles[Y]); + else + { + MoveAbsolute(-3 * CWIDEDOTS, -CHIGHDOTS); + PrintText(AxisTitles[Y], pg, vgOutput); + } AxisTitles[Y] = null; } RecallPosition(); } - - private void DoBoxes(VG.Page pg, C1PdfDocument pdf) + private void DoBoxes(VG.Page pg, IVGOutput vgOutput) { - int dx,dy; - BoxList current; + int dx, dy; + XyBox current; string str; - //string nextstr; SavePosition(); int BoxIdx = 0; SetPenDiameter(5); - while(BoxIdx < AllBoxes.Count) + while (BoxIdx < AllBoxes.Count) { - current=(BoxList)AllBoxes[BoxIdx]; + current = AllBoxes[BoxIdx]; MoveTo(current.BoxMinimum); - dx=current.BoxMaximum.xyValue[X] - current.BoxMinimum.xyValue[X]; -// dy=current.BoxMinimum.xyValue[Y] - current.BoxMaximum.xyValue[Y]; - dy=current.BoxMaximum.xyValue[Y] - current.BoxMinimum.xyValue[Y]; - if( current.Shadow != 2 ) BoxRelative(dx,dy,CurPenWidth,pg,pdf); - if( current.Shadow == 1 ) + dx = current.BoxMaximum.xyValue[X] - current.BoxMinimum.xyValue[X]; + dy = current.BoxMaximum.xyValue[Y] - current.BoxMinimum.xyValue[Y]; + if (current.Shadow != 2) BoxRelative(dx, dy, CurPenWidth, pg, vgOutput); + if (current.Shadow == 1) { int savePenWidth = CurPenWidth; SavePosition(); SetPenDiameter(10); - MoveRelative((int)(10 * ConvertToTwips),-(dy+(int)(5*ConvertToTwips))); - DrawRelative(dx,0,pg,pdf); -// BlockRelative(dx,(int)(10 * ConvertToTwips),pg,pdf); - MoveRelative(-(int)(3 * ConvertToTwips),-(int)(5*ConvertToTwips)); -// BlockRelative((int)(10 * ConvertToTwips),dy,pg,pdf); - DrawRelative(0,dy,pg,pdf); + MoveRelative((int)(10 * ConvertToTwips), -(dy + (int)(5 * ConvertToTwips))); + DrawRelative(dx, 0, pg, vgOutput); + MoveRelative(-(int)(3 * ConvertToTwips), -(int)(5 * ConvertToTwips)); + DrawRelative(0, dy, pg, vgOutput); CurPenWidth = savePenWidth; -// MoveRelative(dx + (int)(10 * ConvertToTwips),0); -// BlockRelative(-dx,(int)(10 * ConvertToTwips),pg,pdf); -// BlockRelative((int)(-10 * ConvertToTwips),dy + (int)(10 * ConvertToTwips),pg,pdf); RecallPosition(); } -//jj MoveRelative((CWIDEDOTS * (3/2)),dy + (CHIGHDOTS * (5/4))); - MoveRelative((CWIDEDOTS * (3/2)),-(CHIGHDOTS * (5/4))); - str=current.BoxText; + MoveRelative((CWIDEDOTS * (3 / 2)), -(CHIGHDOTS * (5 / 4))); + str = current.BoxText; int stridx = 0; - while(stridx < str.Length) + while (stridx < str.Length) { string tstr = str; int idx; - if ((idx = str.IndexOf("\n",stridx)) >= 0) + if ((idx = str.IndexOf("\n", stridx)) >= 0) { - tstr = str.Substring(stridx,idx-stridx); + tstr = str.Substring(stridx, idx - stridx); stridx = idx + 1; } - // if( (nextstr=strchr(str,'\n')) != NULL ) *nextstr++=0; - PrintText(tstr,pg,pdf); - MoveRelative(0,-CHIGHDOTS); - // str=nextstr; + PrintText(tstr, pg, vgOutput); + MoveRelative(0, -CHIGHDOTS); } - // current=current->NextBox; BoxIdx++; } RecallPosition(); } - - private void DrawLines(VG.Page pg, C1PdfDocument pdf) + private void DrawLines(VG.Page pg, IVGOutput vgOutput) { int PlotsIdx = 0; - PointList curpoint; - LineList current; - + DataPoint curpoint; + PlotLine current; SavePosition(); - // if( HPGL_Command[0] ) { - // if( UsePP ) { /* PRINTAPLOT third party software */ - // if( (PRT=fopen("HPGL.tmp","wb")) == NULL ) - // {fprintf(stderr,"Could not open HPGL.tmp");PRT=stdprn;return;} - // HP_FudgeX=PRINTAPLOT_COMPENSATE; - // HP_FudgeY=PRINTAPLOT_COMPENSATE; - // - // } else { /* standard HPGL */ - // PRT=stdprn; - // HP_FudgeX=HP3_HPGL_COMPENSATEX; - // HP_FudgeY=HP3_HPGL_COMPENSATEY; - // } - // HPGLMode=1; - // ANGLELIMIT=2.0; - // fprintf(PRT,HPGL_Command[0]); /* Initialization */ - // - // } else { /* All other printers */ - //PRT=stdprn; - //HPGLMode=0; SetPenDiameter(8); - // } - /* begin plotting the graph lines, which may be straight or curved */ - while(PlotsIdx < AllPlots.Count) + while (PlotsIdx < AllPlots.Count) { - current=(LineList)AllPlots[PlotsIdx]; + current = AllPlots[PlotsIdx]; int pntListIdx = 0; - LineDiv=current.PlotDivisions; - if( current.PlotType == STRAIGHT ) + LineDiv = current.PlotDivisions; + if (current.PlotType == STRAIGHT) { /* straight plot */ - curpoint=(PointList)current.PlotPointsList[pntListIdx]; + curpoint = current.PlotDataPoints[pntListIdx]; MoveTo(curpoint.APoint); - // while( (curpoint=curpoint->NextPoint) != 0 ) - while( ++pntListIdx < current.PlotPointsList.Count ) + while (++pntListIdx < current.PlotDataPoints.Count) { - curpoint = (PointList)current.PlotPointsList[pntListIdx]; - DrawLineTo(curpoint.APoint,pg,pdf); + curpoint = current.PlotDataPoints[pntListIdx]; + DrawLineTo(curpoint.APoint, pg, vgOutput); } - } - else - { - DrawCurve(current,pg,pdf); /* curved plot */ } - - /* HP printers seem to have a bug (or this code does) which */ - /* requires that each plot or curve be redrawn relative to the */ - /* origin, or plot offsetting occurs. */ - // if(HPGLMode && !UsePP) { - // Graphics(0); - // RecallPosition(); - // SavePosition(); - // Graphics(1); - // fprintf(PRT,HPGL_Command[0]); /* Initialization */ - // } - -// current=current.NextPlot; /* point to next curve */ + else + { + DrawCurve(current, pg, vgOutput); /* curved plot */ + } PlotsIdx++; -// if (PlotsIdx < AllPlots.Count) -// current=(LineList)AllPlots[PlotsIdx]; } /* repeat for each plot (while) */ - - // if(HPGLMode) { - // fprintf(PRT,HPGL_Command[1]); /* Cleanup */ - // if( UsePP ) { fclose(PRT); PRT=stdprn; } - // } RecallPosition(); } - - private point FindCenterOfArc(point StartPoint, double Slope1, point EndPoint, double Slope2) + private point FindCenterOfArc(point StartPoint, double Slope1, point EndPoint, double Slope2) { point center = new point(); - double s1,s2; - int x1,y1,x2,y2; - + double s1, s2; + int x1, y1, x2, y2; center.xyValue = new int[Dimensions]; s1 = tan_deg(FixAngle(atan_deg(Slope1))); - s2=tan_deg(FixAngle(atan_deg(Slope2))); - x1=StartPoint.xyValue[X]; - y1=StartPoint.xyValue[Y]; - x2=EndPoint.xyValue[X]; - y2=EndPoint.xyValue[Y]; - center.xyValue[X]=(int)(((s2*s1)*(y2-y1)+(s1*x2)-(s2*x1))/(s1-s2)); - if(s1==0.0) - center.xyValue[Y] = (int)(y2-((center.xyValue[X]-x2)/s2)); + s2 = tan_deg(FixAngle(atan_deg(Slope2))); + x1 = StartPoint.xyValue[X]; + y1 = StartPoint.xyValue[Y]; + x2 = EndPoint.xyValue[X]; + y2 = EndPoint.xyValue[Y]; + center.xyValue[X] = (int)(((s2 * s1) * (y2 - y1) + (s1 * x2) - (s2 * x1)) / (s1 - s2)); + if (s1 == 0.0) + center.xyValue[Y] = (int)(y2 - ((center.xyValue[X] - x2) / s2)); else - center.xyValue[Y] = (int)(y1-((center.xyValue[X]-x1)/s1)); - return(center); + center.xyValue[Y] = (int)(y1 - ((center.xyValue[X] - x1) / s1)); + return (center); } - - private point FindModifiedCenter(double rprime, point PtOnArc, double ang) + private point FindModifiedCenter(double rprime, point PtOnArc, double ang) { point newcenter = new point(); newcenter.xyValue = new int[Dimensions]; newcenter.xyValue[X] = (int)(PtOnArc.xyValue[X] - rprime * cos_deg(ang)); newcenter.xyValue[Y] = (int)(PtOnArc.xyValue[Y] - rprime * sin_deg(ang)); - return(newcenter); + return (newcenter); } - - private int AddMidPoint(ArrayList ptLstAry, int pt1Idx, int pt2Idx) + private int AddMidPoint(DataPoints ptLstAry, int pt1Idx, int pt2Idx) { - PointList midpt; - PointList pt1, pt2; + DataPoint midpt; + DataPoint pt1, pt2; point pt; double so; - int x1,y1,x2,y2; - pt1 = (PointList)ptLstAry[pt1Idx]; - pt2 = (PointList)ptLstAry[pt2Idx]; - x1=pt1.APoint.xyValue[X]; - y1=pt1.APoint.xyValue[Y]; - x2=pt2.APoint.xyValue[X]; - y2=pt2.APoint.xyValue[Y]; - midpt = new PointList(); - pt=new point(); + int x1, y1, x2, y2; + pt1 = ptLstAry[pt1Idx]; + pt2 = ptLstAry[pt2Idx]; + x1 = pt1.APoint.xyValue[X]; + y1 = pt1.APoint.xyValue[Y]; + x2 = pt2.APoint.xyValue[X]; + y2 = pt2.APoint.xyValue[Y]; + midpt = new DataPoint(); + pt = new point(); pt.xyValue = new int[Dimensions]; - so=FindSlope(pt1.APoint,pt2.APoint); - midpt.slope = (4.0 * so - pt1.slope - pt2.slope)/2.0; - pt.xyValue[X]=x1+(x2-x1)/2; - pt.xyValue[Y]=y1+(y2-y1)/2; - midpt.APoint=pt; - ptLstAry.Insert(pt1Idx+1,midpt); - //midpt->NextPoint=pt2; - return(pt1Idx+1); + so = FindSlope(pt1.APoint, pt2.APoint); + midpt.slope = (4.0 * so - pt1.slope - pt2.slope) / 2.0; + pt.xyValue[X] = x1 + (x2 - x1) / 2; + pt.xyValue[Y] = y1 + (y2 - y1) / 2; + midpt.APoint = pt; + ptLstAry.Insert(pt1Idx + 1, midpt); + return (pt1Idx + 1); } - - private double FindTheta(point Endpoint, point Centerpoint) + private double FindTheta(point Endpoint, point Centerpoint) { - double dy,dx,result; + double dy, dx, result; dx = Endpoint.xyValue[X] - Centerpoint.xyValue[X]; dy = Endpoint.xyValue[Y] - Centerpoint.xyValue[Y]; - result=90.0 - atan_deg((dy/dx)); - if( dx<0 ) result+=180.0; - return(result); + result = 90.0 - atan_deg((dy / dx)); + if (dx < 0) result += 180.0; + return (result); } - - private double FindRadius(point Endpoint, point Centerpoint) + private double FindRadius(point Endpoint, point Centerpoint) { - double dy,dx,r; -// double dy,dx,ddx,ddy,r; + double dy, dx, r; dx = Centerpoint.xyValue[X] - Endpoint.xyValue[X]; dy = Centerpoint.xyValue[Y] - Endpoint.xyValue[Y]; - r = Math.Sqrt(((dx*dx)+(dy*dy))); - return(r); + r = Math.Sqrt(((dx * dx) + (dy * dy))); + return (r); } - - - private void DrawCurve(LineList linestart, VG.Page pg, C1PdfDocument pdf) + private void DrawCurve(PlotLine linestart, VG.Page pg, IVGOutput vgOutput) { - //PointList curpoint,pt2; int pltptListIdx = -1; -// int debug = 1; //jj - //curpoint=(PointList)linestart.PlotPointsList[pltptListIdx]; - while( ++pltptListIdx < linestart.PlotPointsList.Count -1 ) + while (++pltptListIdx < linestart.PlotDataPoints.Count - 1) { - DoSubArcs(linestart.PlotPointsList,pltptListIdx,pg,pdf); -// pltptListIdx = linestart.PlotPointsList.Count * debug; // jj -// debug++; //jj - //DoSubArcs(curpoint); - //curpoint=(PointList)linestart.PlotPointsList[pltptListIdx]; + DoSubArcs(linestart.PlotDataPoints, pltptListIdx, pg, vgOutput); } } - - private double GetAngle(double s1) + private double GetAngle(double s1) { double t1; - t1=atan_deg(s1); - return(t1); + t1 = atan_deg(s1); + return (t1); } - - private double GetAngleBetweenPoints(point pt1, point pt2) + private double GetAngleBetweenPoints(point pt1, point pt2) { double retval; - retval=GetAngle(FindSlope(pt1,pt2)); - if(pt2.xyValue[X] < pt1.xyValue[X]) + retval = GetAngle(FindSlope(pt1, pt2)); + if (pt2.xyValue[X] < pt1.xyValue[X]) { - if(retval<0) - retval+=180; + if (retval < 0) + retval += 180; else - retval-=180; + retval -= 180; } - return(retval); + return (retval); } - - private double SpecialGetAngleBetweenPoints(point pt1, point pt2, double s1) + private double SpecialGetAngleBetweenPoints(point pt1, point pt2, double s1) { double retval; - if(s1==0.0) + if (s1 == 0.0) { - if(pt1.xyValue[Y] < pt2.xyValue[Y]) - s1=Convert.ToDouble("1.E99"); + if (pt1.xyValue[Y] < pt2.xyValue[Y]) + s1 = Convert.ToDouble("1.E99"); else - s1=Convert.ToDouble("-1.E99"); - } + s1 = Convert.ToDouble("-1.E99"); + } else - s1 = -1/s1; - retval=GetAngle(s1); - if(pt2.xyValue[X] < pt1.xyValue[X]) + s1 = -1 / s1; + retval = GetAngle(s1); + if (pt2.xyValue[X] < pt1.xyValue[X]) { - if(retval<0) - retval+=180; + if (retval < 0) + retval += 180; else - retval-=180; + retval -= 180; } - return(retval); + return (retval); } - - private double GetArcAngle(double s1, double s2) + private double GetArcAngle(double s1, double s2) { - double result,t1,t2; - t1=GetAngle(s1); - t2=GetAngle(s2); - result=t1-t2; - return(result); + double result, t1, t2; + t1 = GetAngle(s1); + t2 = GetAngle(s2); + result = t1 - t2; + return (result); } - - private void DoSubArcs(ArrayList ptListAry, int aryIdx, VG.Page pg, C1PdfDocument pdf) + private void DoSubArcs(DataPoints dataPoints, int aryIdx, VG.Page pg, IVGOutput vgOutput) { bool debug = false; //jsj - int x,y,x1,x2,y1,y2; - PointList pt1 = (PointList)ptListAry[aryIdx]; - PointList pt2 = (PointList)ptListAry[aryIdx+1]; -#if DEBUG - Console.WriteLine("pt1={0},{1},{2}",pt1.APoint.xyValue[0],pt1.APoint.xyValue[1],pt1.slope); - Console.WriteLine("pt2={0},{1},{2}",pt2.APoint.xyValue[0],pt2.APoint.xyValue[1],pt2.slope); -#endif - double theta,delta1,delta2,r1,r2,t1,t2,theta1,theta2,thetaa,t3,t4; - double c1,c2,s1,s2; -// point cp,cp1,cp2; - point cp1,cp2; - t3=FixAngle(GetAngle(pt1.slope)); - t4=FixAngle(GetAngle(pt2.slope)); - thetaa=GetAngleBetweenPoints(pt1.APoint,pt2.APoint); - if((t3-thetaa)*(t4-thetaa) >= 0.0) + int x, y, x1, x2, y1, y2; + DataPoint pt1 = dataPoints[aryIdx]; + DataPoint pt2 = dataPoints[aryIdx + 1]; + DebugOutput("pt1={0},{1},{2}", pt1.APoint.xyValue[0], pt1.APoint.xyValue[1], pt1.slope); + DebugOutput("pt2={0},{1},{2}", pt2.APoint.xyValue[0], pt2.APoint.xyValue[1], pt2.slope); + double theta, delta1, delta2, r1, r2, t1, t2, theta1, theta2, thetaa, t3, t4; + double c1, c2, s1, s2; + double t3a, t4a; + point cp1, cp2; + t3 = FixAngle(t3a=GetAngle(pt1.slope)); + t4 = FixAngle(t4a=GetAngle(pt2.slope)); + thetaa = GetAngleBetweenPoints(pt1.APoint, pt2.APoint); + if ((t3 - thetaa) * (t4 - thetaa) >= 0.0) { double tprime; - tprime=FixAngle(thetaa); - if (Math.Abs(tprime-t3) < ANGLELIMIT ) + tprime = FixAngle(thetaa); + if (Math.Abs(tprime - t3) < ANGLELIMIT) { MoveTo(pt1.APoint); - DrawTo(pt2.APoint,pg,pdf); + DrawTo(pt2.APoint, pg, vgOutput); return; - } - else + } + else { - pt2=(PointList)ptListAry[AddMidPoint(ptListAry,aryIdx,aryIdx+1)]; - t4=FixAngle(GetAngle(pt2.slope)); - thetaa=GetAngleBetweenPoints(pt1.APoint,pt2.APoint); + pt2 = dataPoints[AddMidPoint(dataPoints, aryIdx, aryIdx + 1)]; + t4 = FixAngle(GetAngle(pt2.slope)); + thetaa = GetAngleBetweenPoints(pt1.APoint, pt2.APoint); } } -// if (debug) //jsj -// return; - - if(thetaa < t3) - t1=t3+90; + if (thetaa < t3) + t1 = t3 + 90; else - t1=t3-90; - if(thetaa > t4) - t2=t4+90; + t1 = t3 - 90; + if (thetaa > t4) + t2 = t4 + 90; else - t2=t4-90; - theta=t2-t1; - theta1=FixAngle(thetaa-t3); - theta2=theta-theta1; - if(Math.Abs(theta1) < Math.Abs(theta2)) + t2 = t4 - 90; + theta = t2 - t1; + theta1 = FixAngle(thetaa - t3); + theta2 = theta - theta1; + if (Math.Abs(theta1) < Math.Abs(theta2)) { - if(Math.Abs(theta1) < ANGLELIMIT ) + if (Math.Abs(theta1) < ANGLELIMIT) { - theta1=0; - theta2=theta; - } - } - else if(Math.Abs(theta2) < Math.Abs(theta1)) - { - if(Math.Abs(theta2) < ANGLELIMIT ) - { - theta2=0; - theta1=theta; + theta1 = 0; + theta2 = theta; } } - x1=pt1.APoint.xyValue[X]; - y1=pt1.APoint.xyValue[Y]; - x2=pt2.APoint.xyValue[X]; - y2=pt2.APoint.xyValue[Y]; - s1=sin_deg(t1+180); - s2=sin_deg(t2+180); - c1=cos_deg(t1+180); - c2=cos_deg(t2+180); - if(s1 == 0.0) + else if (Math.Abs(theta2) < Math.Abs(theta1)) { - r2=(x1-x2)/s2; - r1=(y2+r2*c2-y1)/c1; - } - else if(s2 == 0.0) + if (Math.Abs(theta2) < ANGLELIMIT) + { + theta2 = 0; + theta1 = theta; + } + } + x1 = pt1.APoint.xyValue[X]; + y1 = pt1.APoint.xyValue[Y]; + x2 = pt2.APoint.xyValue[X]; + y2 = pt2.APoint.xyValue[Y]; + s1 = sin_deg(t1 + 180); + s2 = sin_deg(t2 + 180); + c1 = cos_deg(t1 + 180); + c2 = cos_deg(t2 + 180); + if (s1 == 0.0) { - r1=(x2-x1)/s1; - r2=(y1+r1*c1-y2)/c2; - } - else if(c1 == 0.0) + r2 = (x1 - x2) / s2; + r1 = (y2 + r2 * c2 - y1) / c1; + } + else if (s2 == 0.0) { - r2=(y1-y2)/c2; - r1=(x2+r2*s2-x1)/s1; - } - else if(c2 == 0.0) + r1 = (x2 - x1) / s1; + r2 = (y1 + r1 * c1 - y2) / c2; + } + else if (c1 == 0.0) { - r1=(y2-y1)/c1; - r2=(x1+r1*s1-x2)/s2; - } - else + r2 = (y1 - y2) / c2; + r1 = (x2 + r2 * s2 - x1) / s1; + } + else if (c2 == 0.0) { - r2=(((x2-x1)/c1) - ((y2-y1)/s1)) / (s2/s1 - c2/c1); - r1=(y2-y1+r2*s2)/s1; + r1 = (y2 - y1) / c1; + r2 = (x1 + r1 * s1 - x2) / s2; + } + else + { + r2 = (((x2 - x1) / c1) - ((y2 - y1) / s1)) / (s2 / s1 - c2 / c1); + r1 = (y2 - y1 + r2 * s2) / s1; } MoveTo(pt1.APoint); if (debug) //jsj { - DrawTo(pt2.APoint,pg,pdf); + DrawTo(pt2.APoint, pg, vgOutput); return; } - if(Math.Abs(theta1)>ANGLELIMIT && Math.Abs(theta2)>ANGLELIMIT) + if (Math.Abs(theta1) > ANGLELIMIT && Math.Abs(theta2) > ANGLELIMIT) { - delta1=(r2-r1)/( - (1.0-cos_deg(theta1)) + - (1.0-cos_deg(theta2))*sin_deg(theta1)/sin_deg(theta2)); - r1=Math.Floor(0.5+r1+delta1); - cp1=FindModifiedCenter(r1,pt1.APoint,t1); -// cp1 = FindCenterOfArc(pt1.APoint,pt1.slope,pt2.APoint,pt2.slope); // jj - x=(int)(cp1.xyValue[X]+r1*cos_deg(t1+theta1)); - y=(int)(cp1.xyValue[Y]+r1*sin_deg(t1+theta1)); - delta2=delta1*sin_deg(theta1)/sin_deg(theta2); -// x = pt2.APoint.xyValue[X]; //jj -// y = pt2.APoint.xyValue[Y]; //jj - r2=Math.Floor(0.5+r2-delta2); - cp2=FindModifiedCenter(r2,pt2.APoint,t2); -#if DEBUG - Console.WriteLine("DrawArc1"); -#endif - DrawArc(r1,t1,t1+theta1,cp1,x,y,pg,pdf); + delta1 = (r2 - r1) / ( + (1.0 - cos_deg(theta1)) + + (1.0 - cos_deg(theta2)) * sin_deg(theta1) / sin_deg(theta2)); + r1 = Math.Floor(0.5 + r1 + delta1); + cp1 = FindModifiedCenter(r1, pt1.APoint, t1); + x = (int)(cp1.xyValue[X] + r1 * cos_deg(t1 + theta1)); + y = (int)(cp1.xyValue[Y] + r1 * sin_deg(t1 + theta1)); + delta2 = delta1 * sin_deg(theta1) / sin_deg(theta2); + r2 = Math.Floor(0.5 + r2 - delta2); + cp2 = FindModifiedCenter(r2, pt2.APoint, t2); + DebugOutput("DrawArc1"); VG_Arc.iColor = 1; + DrawArc(r1, t1, t1 + theta1, cp1, x, y, pg, vgOutput); + DebugShowLocation("DrawArc1"); MoveTo(pt2.APoint); - if(r2 > 15000) + DebugShowLocation("MoveTo1"); + if (r2 > 15000) { -#if DEBUG - Console.WriteLine("DrawAbs1 {0},{1}",x,y); -#endif - DrawAbsolute(x,y,pg,pdf); + DebugOutput("DrawAbs1 {0},{1}", x, y); + DrawAbsolute(x, y, pg, vgOutput); + DebugShowLocation("DrawAbs1"); } else { -#if DEBUG - Console.WriteLine("DrawArc2"); -#endif - DrawArc(r2,t2,t2-theta2,cp2,x,y,pg,pdf); + DebugOutput("DrawArc2"); VG_Arc.iColor = 2; + DrawArc(r2, t2, t2 - theta2, cp2, x, y, pg, vgOutput); + DebugShowLocation("DrawArc2"); } -// // Zfree(&cp1); -// // Zfree(&cp2); - } - else if(Math.Abs(theta1)>ANGLELIMIT) + } + else if (Math.Abs(theta1) > ANGLELIMIT) { - delta1=(r2-r1)/(1.0-cos_deg(theta1)); - r1=Math.Floor(0.5+r1+delta1); - cp1=FindModifiedCenter(r1,pt1.APoint,t1); -// cp1=FindCenterOfArc(pt1.APoint,pt1.slope,pt2.APoint,pt2.slope); //jj - x=(int)(cp1.xyValue[X]+r1*cos_deg(t1+theta1)); - y=(int)(cp1.xyValue[Y]+r1*sin_deg(t1+theta1)); - if(r1 > 15000) + delta1 = (r2 - r1) / (1.0 - cos_deg(theta1)); + r1 = Math.Floor(0.5 + r1 + delta1); + if (r1 < 0) r1 = -r1; + cp1 = FindModifiedCenter(r1, pt1.APoint, t1); + x = (int)(cp1.xyValue[X] + r1 * cos_deg(t1 + theta1)); + y = (int)(cp1.xyValue[Y] + r1 * sin_deg(t1 + theta1)); + if (r1 > 15000) { -#if DEBUG - Console.WriteLine("DrawAbs2"); -#endif - DrawAbsolute(x,y,pg,pdf); + DebugOutput("DrawAbs2"); + DrawAbsolute(x, y, pg, vgOutput); + DebugShowLocation("DrawAbs2"); } else { -#if DEBUG - Console.WriteLine("DrawArc3"); -#endif - DrawArc(r1,t1,t1+theta1,cp1,x,y,pg,pdf); + //Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", t3, t3a, t4, t4a, thetaa, t1, t2, r1, r2, aryIdx); + DebugOutput("DrawArc3"); VG_Arc.iColor = 3; + VG_Arc.iColor = 4; + DrawArc(r1, t1, t1 + theta1, cp1, x, y, pg, vgOutput); + Console.WriteLine("'DrawArc3','{0}',{1},{2}", Key, r1, theta1); + DebugShowLocation("DrawArc3"); } - MoveAbsolute(x,y); -#if DEBUG - Console.WriteLine("DrawTo1"); -#endif - DrawTo(pt2.APoint,pg,pdf); -// x = pt2.APoint.xyValue[X]; //jj -// y = pt2.APoint.xyValue[Y]; //jj -#if DEBUG - Console.WriteLine("DrawArc4"); -#endif - DrawArc(r1,t1,t1+theta1,cp1,x,y,pg,pdf); - // Zfree(&cp1); - - } - else if(Math.Abs(theta2)>ANGLELIMIT) + MoveAbsolute(x, y); + DebugShowLocation("MoveAbs2"); + DebugOutput("DrawTo1"); + DrawTo(pt2.APoint, pg, vgOutput); + DebugShowLocation("DrawTo1"); + //DebugOutput("DrawArc4"); VG_Arc.iColor = 4; + //DrawArc(r1, t1, t1 + theta1, cp1, x, y, pg, vgOutput); + //DebugShowLocation("DrawArc4"); + } + else if (Math.Abs(theta2) > ANGLELIMIT) { - delta2=(r2-r1)/(1.0-cos_deg(theta2)); - r2=Math.Floor(0.5+r2-delta2); - cp2=FindModifiedCenter(r2,pt2.APoint,t2); -// cp2=FindCenterOfArc(pt1.APoint,pt1.slope,pt2.APoint,pt2.slope); //jj - x=(int)(cp2.xyValue[X]+r2*cos_deg(t2-theta2)); - y=(int)(cp2.xyValue[Y]+r2*sin_deg(t2-theta2)); -#if DEBUG - Console.WriteLine("DrawAbs3"); -#endif - DrawAbsolute(x,y,pg,pdf); + delta2 = (r2 - r1) / (1.0 - cos_deg(theta2)); + r2 = Math.Floor(0.5 + r2 - delta2); + if (r2 < 0) r2 = -r2; + cp2 = FindModifiedCenter(r2, pt2.APoint, t2); + x = (int)(cp2.xyValue[X] + r2 * cos_deg(t2 - theta2)); + y = (int)(cp2.xyValue[Y] + r2 * sin_deg(t2 - theta2)); + DebugOutput("DrawAbs3"); + DrawAbsolute(x, y, pg, vgOutput); + DebugShowLocation("DrawAbs3"); MoveTo(pt2.APoint); - if(r2 > 15000) + DebugShowLocation("MoveTo1"); + if (r2 > 15000) { -#if DEBUG - Console.WriteLine("DrawAbs4"); -#endif - DrawAbsolute(x,y,pg,pdf); + DebugOutput("DrawAbs4"); + DrawAbsolute(x, y, pg, vgOutput); + DebugShowLocation("DrawAbs4"); } else { -#if DEBUG - Console.WriteLine("DrawArc5"); -#endif - DrawArc(r2,t2,t2-theta2,cp2,x,y,pg,pdf); + DebugOutput("DrawArc5"); VG_Arc.iColor = 5; + VG_Arc.iColor = 6; + DrawArc(r2, t2, t2 - theta2, cp2, x, y, pg, vgOutput); + DebugShowLocation("DrawArc5"); } -// x = pt2.APoint.xyValue[X]; //jj -// y = pt2.APoint.xyValue[Y]; //jj -#if DEBUG - Console.WriteLine("DrawArc6"); -#endif - DrawArc(r2,t2,t2-theta2,cp2,x,y,pg,pdf); - // Zfree(&cp2); - - } - else + //DebugOutput(""); VG_Arc.iColor = 6; + //DrawArc(r2, t2, t2 - theta2, cp2, x, y, pg, vgOutput); + //DebugShowLocation("DrawArc6"); + } + else { -#if DEBUG - Console.WriteLine("DrawTo2"); -#endif - DrawTo(pt2.APoint,pg,pdf); - pt2.slope=FindSlope(pt1.APoint,pt2.APoint); + DebugOutput("DrawTo2"); + DrawTo(pt2.APoint, pg, vgOutput); + DebugShowLocation("DrawTo2"); + pt2.slope = FindSlope(pt1.APoint, pt2.APoint); } return; } - - private void SetPenDiameter(int pd) + private void SetPenDiameter(int pd) { - if ((pd * ConvertToTwips) != CurPenWidth) + if ((pd * ConvertToTwips) != CurPenWidth) { - CurPenWidth= (int)(pd * ConvertToTwips); + CurPenWidth = (int)(pd * ConvertToTwips); } } - - private void PrintStackError(string relation, int limit) + private void PrintStackError(string relation, int limit) { - MessageBox.Show(String.Format("Position Stack Pointer {0} {1}",relation,limit.ToString()),"Print Stack Error"); - // printf("Position Stack Pointer %s %d",relation,limit); - // spc_exit(3); + MessageBox.Show(String.Format("Position Stack Pointer {0} {1}", relation, limit.ToString()), "Print Stack Error"); } - - private void SavePosition() + private void SavePosition() { - if(stack >= MAX_XY_STACK) PrintStackError(">=",MAX_XY_STACK); - SavedX[stack]=Position[X]; - SavedY[stack++]=Position[Y]; + if (stack >= MAX_XY_STACK) PrintStackError(">=", MAX_XY_STACK); + SavedX[stack] = Position[X]; + SavedY[stack++] = Position[Y]; } - - private void RecallPosition() + private void RecallPosition() { - if(stack <= 0) PrintStackError(" <",0); - Position[X]=SavedX[--stack]; - Position[Y]=SavedY[stack]; + if (stack <= 0) PrintStackError(" <", 0); + Position[X] = SavedX[--stack]; + Position[Y] = SavedY[stack]; } - - private void MoveTo(point pnt) + private void MoveTo(point pnt) { - MoveAbsolute(pnt.xyValue[X],pnt.xyValue[Y]); + MoveAbsolute(pnt.xyValue[X], pnt.xyValue[Y]); } - - private void DrawTo(point pnt, VG.Page pg, C1PdfDocument pdf) + private void DrawTo(point pnt, VG.Page pg, IVGOutput vgOutput) { - DrawAbsolute(pnt.xyValue[X],pnt.xyValue[Y],pg,pdf); + DrawAbsolute(pnt.xyValue[X], pnt.xyValue[Y], pg, vgOutput); } - - private void MoveAbsolute(int ptx, int pty) + private void MoveAbsolute(int ptx, int pty) { - int x,y; - x=ptx-Position[X]; - y=Position[Y]-pty; - MoveRelative(x,y); + int x, y; + x = ptx - Position[X]; + y = Position[Y] - pty; + MoveRelative(x, y); } - - private void DrawAbsolute(int ptx, int pty, VG.Page pg, C1PdfDocument pdf) + private void DrawAbsolute(int ptx, int pty, VG.Page pg, IVGOutput vgOutput) { - int x,y; - x=ptx-Position[X]; - y=Position[Y]-pty; - DrawRelative(x,y,pg,pdf); + int x, y; + x = ptx - Position[X]; + y = Position[Y] - pty; + DrawRelative(x, y, pg, vgOutput); } - - private void DrawGridAbsolute(int ptx, int pty, VG.Page pg, C1PdfDocument pdf) + private void DrawGridAbsolute(int ptx, int pty, VG.Page pg, IVGOutput vgOutput) { - int x,y; - x=ptx-Position[X]; - y=Position[Y]-pty; - DrawGridRelative(x,y,pg,pdf); + int x, y; + x = ptx - Position[X]; + y = Position[Y] - pty; + DrawGridRelative(x, y, pg, vgOutput); } - - private void relval(string ptr, int i) + private void relval(string ptr, int i) { - ptr = string.Format("+{0}",i.ToString()); + ptr = string.Format("+{0}", i.ToString()); } - - private void MoveRelative(int x, int y) + private void MoveRelative(int x, int y) { - long xl,yl; - Position[X]+=x; - Position[Y]-=y; + Position[X] += x; + Position[Y] -= y; } - - private void DrawRelative(int x, int y, VG.Page pg, C1PdfDocument pdf) + private void DrawRelative(int x, int y, VG.Page pg, IVGOutput vgOutput) { -// long xl,yl; - if(Visible == 0) - MoveRelative(x,y); - else + if (Visible == 0) + MoveRelative(x, y); + else { int toX, toY; - toX = Position[X]+x; - toY = Position[Y]-y; -// toY = Position[Y]+y; - VG_Line RelLine = new VG_Line(Position[X],Position[Y],toX,toY,CurPenWidth,pg); -// VG_Line RelLine = new VG_Line(Position[X],Position[Y],x,-y,CurPenWidth,pg); - Position[X]+=x; - Position[Y]-=y; -// Position[Y]+=y; - RelLine.ToPdf(pdf); -// if(HPGLMode != 0) -// { -// xl=DotsToPlotterUnitsX(x); -// yl=DotsToPlotterUnitsY(y); -// // !!! OUTPUT DRAW RELATIVE COMMAND -// MessageBox.Show("!!! OUTPUT DRAW RELATIVE COMMAND 1","DrawRelative()"); -// // fprintf(PRT,HPGL_Command[3],-xl,yl); /* */ -// } -// else -// MessageBox.Show("!!! OUTPUT DRAW RELATIVE COMMAND 2","DrawRelative()"); -// // !!! OUTPUT DRAW RELATIVE COMMAND -// // fprintf(PRT,graph_DrawRelative,x,y); + toX = Position[X] + x; + toY = Position[Y] - y; + VG_Line RelLine = new VG_Line(Position[X], Position[Y], toX, toY, CurPenWidth, pg); + Position[X] += x; + Position[Y] -= y; + RelLine.Draw(vgOutput); } } - - private void DrawGridRelative(int x, int y, VG.Page pg, C1PdfDocument pdf) + private void DrawGridRelative(int x, int y, VG.Page pg, IVGOutput vgOutput) { - if(Visible == 0) - MoveRelative(x,y); - else + if (Visible == 0) + MoveRelative(x, y); + else { -/*** - if(StupidHP == 2) - { //StupidHP==5 is RTF driver - if(x==0) BlockRelative(PrevPen,y); - else if(y==0) BlockRelative(x,PrevPen); - MoveRelative(x,y); - - } - else -***/ - DrawRelative(x,y,pg,pdf); + DrawRelative(x, y, pg, vgOutput); } } - - private void MoveForArc(point pnt) + private void MoveForArc(point pnt) { - Position[X]+=pnt.xyValue[X]; - Position[Y]-=pnt.xyValue[Y]; + Position[X] += pnt.xyValue[X]; + Position[Y] -= pnt.xyValue[Y]; } - - private void DrawArc(double radius, double Sangle, double Eangle, point cp, int x, int y, VG.Page pg, C1PdfDocument pdf) + private void DrawArc(double radius, double Sangle, double Eangle, point cp, int x, int y, VG.Page pg, IVGOutput vgOutput) { -#if DEBUG - Console.WriteLine("r={0} sAngle={1} eAngle={2} cp={3},{4} x={5} y={6}",radius,Sangle,Eangle,cp.xyValue[0],cp.xyValue[1],x,y); -#endif - // double inc=2000.,r1; - int dx,dy; + DebugOutput("r={0} sAngle={1} eAngle={2} cp={3},{4} x={5} y={6}", radius, Sangle, Eangle, cp.xyValue[0], cp.xyValue[1], x, y); + int dx, dy; long radchk; - radchk=(long)radius; -// if(radchk > 15000L) - if(radchk > 72000L) + radchk = (long)radius; + if (radchk > 72000L) { - DrawAbsolute(x,y,pg,pdf); + DrawAbsolute(x, y, pg, vgOutput); return; } dx = x - cp.xyValue[X]; //jj -// dx=cp.xyValue[X]-Position[X]; -// dy=cp.xyValue[Y]-Position[Y]; - dy=Math.Abs(cp.xyValue[Y]-Position[Y]); //jj - //r1=radius; - /* - ** for the HP series of printers we recalculate the the x and y positions - ** because of a rounding error that will propagate every time - ** an arc segment is drawn. This has the nasty effect of incorrectly - ** drawing curves. - */ -// if( HPGLMode != 0 ) -// { -// Position[X] += (int)((radius*cos_deg(Eangle) - radius*cos_deg(Sangle))); -// Position[Y] -= (int)((radius*sin_deg(Sangle) - radius*sin_deg(Eangle))); -// } -// Sangle=90-Sangle; -// Eangle=90-Eangle; -// Sangle=180-Sangle; //jj -// Eangle=180-Eangle; //jj - -// if(HPGLMode != 0) -// { -// long xl,yl; -// xl=DotsToPlotterUnitsX(dx); -// yl=DotsToPlotterUnitsY(dy); - // fprintf(PRT,HPGL_Command[4],-xl,-yl,(int)(Sangle-Eangle)); -// VG_Arc arc = new VG_Arc(cp.xyValue[X]-dx,cp.xyValue[Y]+dy,dx*2,dy*2,(float)Sangle,(float)(Sangle - Eangle),5,pg); -// VG_Arc arc = new VG_Arc(cp.xyValue[X]-dx,cp.xyValue[Y]-dy,dx*2,dy*2,(float)Sangle,(float)(Sangle - Eangle),CurPenWidth,pg); - radius=radius; - float x1=cp.xyValue[X]-(float)radius; - float y1=cp.xyValue[Y]-(float)radius; - float w1=(float) radius * 2; - VG_Arc arc = new VG_Arc(x1,y1,w1,w1,(float)Sangle,(float)(Eangle - Sangle),CurPenWidth,pg); - //VG_Arc arc = new VG_Arc(0,0,5000,5000,(float)Sangle,(float)(Eangle - Sangle),CurPenWidth,pg); -#if DEBUG - Console.WriteLine("arc {0},{1},{2},{3},{4},{5}",x1,y1,w1,w1,(float)Sangle,(float)(Eangle - Sangle)); -#endif - arc.ToPdf(pdf); -// MessageBox.Show("!!! HPGL_COMMAND[4]","DrawArc()"); -// } -// else -// { -// SavePosition(); -// if(dx>0) -// MessageBox.Show("!!! graph_MoveRelativeXPos","DrawArc()"); -// // fprintf(PRT,graph_MoveRelativeXPos,dx); -// else -// MessageBox.Show("!!! graph_MoveRelativeXNeg","DrawArc()"); -// // fprintf(PRT,graph_MoveRelativeXNeg,-dx); -// if(dy>0) -// MessageBox.Show("!!! graph_MoveRelativeYPos","DrawArc()"); -// // fprintf(PRT,graph_MoveRelativeYPos,dy); -// else -// MessageBox.Show("!!! graph_MoveRelativeYNeg","DrawArc()"); -// // fprintf(PRT,graph_MoveRelativeYNeg,-dy); -// MessageBox.Show("!!! graph_ArcFunction1","DrawArc()"); -// // fprintf(PRT,graph_ArcFunction1, -// // radius-4,(radius+4),FMin(Sangle,Eangle),FMax(Sangle,Eangle)); -// RecallPosition(); -// } + dy = Math.Abs(cp.xyValue[Y] - Position[Y]); //jj + float x1 = cp.xyValue[X] - (float)radius; + float y1 = cp.xyValue[Y] - (float)radius; + float w1 = (float)radius * 2; + VG_Arc arc = new VG_Arc(x1, y1, w1, w1, (float)Sangle, (float)(Eangle - Sangle), CurPenWidth, pg); + DebugOutput("arc {0},{1},{2},{3},{4},{5}", x1, y1, w1, w1, (float)Sangle, (float)(Eangle - Sangle)); + arc.Draw(vgOutput); } - - private void DrawGridLine(int flag, int val, VG.Page pg, C1PdfDocument pdf) + private void DrawGridLine(int flag, int val, VG.Page pg, IVGOutput vgOutput) { - ActiveBoxList curbox; - int v1,v2; + XyBox curbox; + int v1, v2; int BoxesIdx = 0; - int BoxPtrIdx = 0; -// FindBoxesinArea(val, !flag); - FindBoxesinArea(val,(flag==0)?1:0); - v1=Position[flag]; - if (AllActiveBoxes.Count > 0) + FindBoxesinArea(val, (flag == 0) ? 1 : 0); + v1 = Position[flag]; + if (ActiveBoxes.Count > 0) { - curbox=(ActiveBoxList)AllActiveBoxes[BoxesIdx]; - while(BoxesIdx < AllActiveBoxes.Count) + curbox = ActiveBoxes[BoxesIdx]; + while (BoxesIdx < ActiveBoxes.Count) { int my_x, my_y; - v2=((BoxList)curbox.BoxPtr[BoxPtrIdx]).BoxMinimum.xyValue[flag]; - my_x = (flag==X)? ( (v2 < printerunits[flag])? v2 : printerunits[flag] ) + v2 = curbox.BoxMinimum.xyValue[flag]; + my_x = (flag == X) ? ((v2 < printerunits[flag]) ? v2 : printerunits[flag]) : val; - my_y = (flag==Y) ? - ( (v2 < printerunits[flag]) ? v2 : printerunits[flag] ) + my_y = (flag == Y) ? + ((v2 < printerunits[flag]) ? v2 : printerunits[flag]) : val; - DrawGridAbsolute(my_x,my_y,pg,pdf); - v1=((BoxList)curbox.BoxPtr[BoxPtrIdx]).BoxMaximum.xyValue[flag]; - while((BoxesIdx < AllActiveBoxes.Count) && (((BoxList)curbox.BoxPtr[BoxPtrIdx]).BoxMinimum.xyValue[flag] < v1)) + DrawGridAbsolute(my_x, my_y, pg, vgOutput); + v1 = curbox.BoxMaximum.xyValue[flag]; + while ((BoxesIdx < ActiveBoxes.Count) && (curbox.BoxMinimum.xyValue[flag] < v1)) { - v1=(((BoxList)curbox.BoxPtr[BoxPtrIdx]).BoxMaximum.xyValue[flag]); + v1 = (curbox.BoxMaximum.xyValue[flag]); BoxesIdx++; - if (BoxesIdx < AllActiveBoxes.Count) - curbox=(ActiveBoxList)AllActiveBoxes[BoxesIdx]; + if (BoxesIdx < ActiveBoxes.Count) + curbox = ActiveBoxes[BoxesIdx]; } - MoveAbsolute((flag==X?v1:val),(flag==Y?v1:val)); + MoveAbsolute((flag == X ? v1 : val), (flag == Y ? v1 : val)); } } - v2=printerunits[flag]; - if (v1 < v2) DrawGridAbsolute((flag==X?v2:val),(flag==Y?v2:val),pg,pdf); - FreeActiveBoxes(); + v2 = printerunits[flag]; + if (v1 < v2) DrawGridAbsolute((flag == X ? v2 : val), (flag == Y ? v2 : val), pg, vgOutput); + ActiveBoxes.Clear(); } - - private void LogScale(int flag) + private void LogScale(int flag) { - double newminimum, newmaximum, maxlimit=maximum[flag]*.9; -// int i; - newminimum=1.0; - while(newminimum < minimum[flag])newminimum *= 10.0; - while(newminimum > minimum[flag])newminimum /= 10.0; - newmaximum=10.0 * newminimum; - cycles[flag]=1; - while( newmaximum < maxlimit ) + double newminimum, newmaximum, maxlimit = maximum[flag] * .9; + newminimum = 1.0; + while (newminimum < minimum[flag]) newminimum *= 10.0; + while (newminimum > minimum[flag]) newminimum /= 10.0; + newmaximum = 10.0 * newminimum; + cycles[flag] = 1; + while (newmaximum < maxlimit) { newmaximum *= 10.0; cycles[flag]++; } - onecycle[flag]=printerunits[flag]/cycles[flag]; - minimum[flag]=newminimum; - maximum[flag]=newmaximum; + onecycle[flag] = printerunits[flag] / cycles[flag]; + minimum[flag] = newminimum; + maximum[flag] = newmaximum; } - - private void LinearScale(int flag) + private void LinearScale(int flag) { - double mantissa,nx; + double mantissa, nx; double newminimum, newmaximum; - int power=0; - if( spcminor[flag] == 0 ) - minor[flag]=10; + int power = 0; + if (spcminor[flag] == 0) + minor[flag] = 10; else - minor[flag]=spcminor[flag]; - if( delta[flag] == 0 ) + minor[flag] = spcminor[flag]; + if (delta[flag] == 0) { - delta[flag]=maximum[flag]-minimum[flag]; - mantissa=Math.Log10(delta[flag]); - while(mantissa < 1.2) + delta[flag] = maximum[flag] - minimum[flag]; + mantissa = Math.Log10(delta[flag]); + while (mantissa < 1.2) { mantissa++; power--; } - while(mantissa > 1.2) + while (mantissa > 1.2) { mantissa--; power++; } - if(mantissa < 0)mantissa=0; - nx=Math.Pow(10.0,mantissa); - if(nx > 5.0) + if (mantissa < 0) mantissa = 0; + nx = Math.Pow(10.0, mantissa); + if (nx > 5.0) { - delta[flag]=1.0; - } - else if(nx > 3.001) - { // allow for roundoff - delta[flag]=0.5; - } - else if(nx > 2.001) - { // allow for roundoff - delta[flag]=0.25; - } - else - { - delta[flag]=0.2; - if(spcminor[flag] == 0) minor[flag]=8; + delta[flag] = 1.0; } - while(power>0) + else if (nx > 3.001) + { // allow for roundoff + delta[flag] = 0.5; + } + else if (nx > 2.001) + { // allow for roundoff + delta[flag] = 0.25; + } + else + { + delta[flag] = 0.2; + if (spcminor[flag] == 0) minor[flag] = 8; + } + while (power > 0) { power--; delta[flag] *= 10.0; } - while(power<0) + while (power < 0) { power++; delta[flag] /= 10.0; } } - if(GridOnFlag==0 || GridOnFlag==1) - minor[flag]=1; - else if(GridOnFlag==2) + if (GridOnFlag == 0 || GridOnFlag == 1) + minor[flag] = 1; + else if (GridOnFlag == 2) minor[flag] /= 2; - newminimum=((int)(0.01+minimum[flag]/delta[flag])) * delta[flag]; - if(newminimum > minimum[flag]+(delta[flag] * 0.001)) - newminimum-=delta[flag]; - newmaximum=((int)(maximum[flag]/delta[flag])) * delta[flag]; - if(newmaximum < maximum[flag]-(delta[flag] * 0.001)) - newmaximum+=delta[flag]; - minimum[flag]=newminimum; - maximum[flag]=newmaximum; + newminimum = ((int)(0.01 + minimum[flag] / delta[flag])) * delta[flag]; + if (newminimum > minimum[flag] + (delta[flag] * 0.001)) + newminimum -= delta[flag]; + newmaximum = ((int)(maximum[flag] / delta[flag])) * delta[flag]; + if (newmaximum < maximum[flag] - (delta[flag] * 0.001)) + newmaximum += delta[flag]; + minimum[flag] = newminimum; + maximum[flag] = newmaximum; } - - private void err_exit(string msg, string msg2) + private void err_exit(string msg, string msg2) { - MessageBox.Show(msg + "\n" + msg2 + "\n\n This p=Process Will Terminate","\n## ERROR ## - "); + MessageBox.Show(msg + "\n" + msg2 + "\n\n This p=Process Will Terminate", "\n## ERROR ## - "); Environment.Exit(255); } - - private void FindBoxesinArea(int ptval, int flag) + private void FindBoxesinArea(int ptval, int flag) { - BoxList cptr; - int BoxesIdx =0; - while (BoxesIdx < AllBoxes.Count) + XyBox cptr; + int BoxesIdx = 0; + while (BoxesIdx < AllBoxes.Count) { - cptr= (BoxList)AllBoxes[BoxesIdx]; - if ( cptr.BoxMinimum.xyValue[flag] <= ptval && - cptr.BoxMaximum.xyValue[flag] >= ptval ) + cptr = AllBoxes[BoxesIdx]; + if (cptr.BoxMinimum.xyValue[flag] <= ptval && + cptr.BoxMaximum.xyValue[flag] >= ptval) AddBoxToActiveList(cptr); BoxesIdx++; } } - - private void AddBoxToActiveList(BoxList bptr) + private void AddBoxToActiveList(XyBox box) { - ActiveBoxList NewActiveBox = new ActiveBoxList(); - int prevboxIdx = -1; - ActiveBoxList cbox; - - NewActiveBox.BoxPtr = new ArrayList(); - NewActiveBox.BoxPtr.Add(bptr); - int AllActBoxIdx = 0; - if( AllActiveBoxes.Count > 0 ) + int i = 0; + while (i < ActiveBoxes.Count) { - cbox = (ActiveBoxList)AllActiveBoxes[AllActBoxIdx]; - prevboxIdx = 0; - while ( AllActBoxIdx < AllActiveBoxes.Count && - (cbox.BoxPtr.Count > 0 && (bptr.BoxMinimum.xyValue[DrawDirection] > - ((BoxList)cbox.BoxPtr[AllActBoxIdx]).BoxMinimum.xyValue[DrawDirection])) ) - { - prevboxIdx=AllActBoxIdx; - AllActBoxIdx++; - if (AllActBoxIdx < AllActiveBoxes.Count) - cbox=(ActiveBoxList)AllActiveBoxes[AllActBoxIdx]; - else - prevboxIdx = -1; // will append to end of list - } - if (AllActBoxIdx < AllActiveBoxes.Count) - AllActiveBoxes.Insert(AllActBoxIdx,NewActiveBox); + if (box.BoxMinimum.xyValue[DrawDirection] < ActiveBoxes[i].BoxMinimum.xyValue[DrawDirection]) + break; // Located the location to insert the box + i++; } - if(prevboxIdx == -1) - AllActiveBoxes.Add(NewActiveBox); - + ActiveBoxes.Insert(i, box); } - - private void FreeActiveBoxes() + private void GenGrid(int flag, int ss, int ee, int dd, int w, int lw, int goffset, VG.Page pg, IVGOutput vgOutput) { - AllActiveBoxes.Clear(); - } - - private void GenGrid(int flag, int ss, int ee, int dd, int w, int lw, int goffset, VG.Page pg, C1PdfDocument pdf) - { - int val,wn,valn; + int val, wn, valn; double p2; -// double p2,size; - int n,dn,MinorGrid=0; - if((GridOnFlag * lw)<=1)return; - if (ee/ss == 10) MinorGrid=2; - n=ss; - p2=n; -// w = (int)(Math.Log10(ee/p2) / w); //jj - w = (int)(w / Math.Log10(ee/p2)); //jj -// w /= (int)Math.Log10(ee/p2); - val=(int)(Math.Log10(p2/ss)*w + goffset); - MoveAbsolute((flag==X?val:0),(flag==Y?val:0)); - DrawGridLine((flag==0)?1:0,val,pg,pdf); - if((GridOnFlag * lw) == 2)return; + int n, dn, MinorGrid = 0; + if ((GridOnFlag * lw) <= 1) return; + if (ee / ss == 10) MinorGrid = 2; + n = ss; + p2 = n; + w = (int)(w / Math.Log10(ee / p2)); //jj + val = (int)(Math.Log10(p2 / ss) * w + goffset); + MoveAbsolute((flag == X ? val : 0), (flag == Y ? val : 0)); + DrawGridLine((flag == 0) ? 1 : 0, val, pg, vgOutput); + if ((GridOnFlag * lw) == 2) return; SetPenDiameter(lw); - while(n < ee) + while (n < ee) { - n+=dd; - p2=n; - valn=(int)(Math.Log10(p2/ss)*w + goffset); - wn=valn-val; - if(wn > DPI/20 && lw > 1) + n += dd; + p2 = n; + valn = (int)(Math.Log10(p2 / ss) * w + goffset); + wn = valn - val; + if (wn > DPI / 20 && lw > 1) { - if(wn > DPI*2/5)dn=dd/10; - else if(wn > DPI/5) dn=dd/5; - else dn=dd/2; - GenGrid(flag,n-dd,n,dn,wn,lw-1,val,pg,pdf); - wn=0; + if (wn > DPI * 2 / 5) dn = dd / 10; + else if (wn > DPI / 5) dn = dd / 5; + else dn = dd / 2; + GenGrid(flag, n - dd, n, dn, wn, lw - 1, val, pg, vgOutput); + wn = 0; } - val=valn; - if (flag ==Y) + val = valn; + if (flag == Y) val = printerunits[Y] - val; //jj - MoveAbsolute((flag==X?val:0),(flag==Y?val:0)); - if((MinorGrid != 0) && (MinorGrid < 10)) + MoveAbsolute((flag == X ? val : 0), (flag == Y ? val : 0)); + if ((MinorGrid != 0) && (MinorGrid < 10)) { -// SavePosition(); -// double SaveFontPitch = FontPitch; //jj - // fprintf(PRT,graph_MinorMark[flag],MinorGrid++); -// if (flag == 0) -// MoveRelative((int)(15 * ConvertToTwips),(int)(60 * ConvertToTwips)); // these numbers are in dots -// else -// MoveRelative((int)(-30 * ConvertToTwips),(int)(9 * ConvertToTwips)); -// FontPitch = 5.0; //jj -// if (flag == 0) -// MoveRelative(0,160); // these numbers are in dots -//// MoveRelative(0,40); // these numbers are in dots -// else -// MoveRelative(-30,0); -// SavePosition(); -// if (flag == 0) -// MoveRelative(30,0); // these numbers are in dots -// else -// MoveRelative(0,0); - WriteValue(flag,MinorGrid++,true,pg,pdf); //these numbers are in dots - // FontPitch = SaveFontPitch; //jj -// RecallPosition(); + WriteValue(flag, MinorGrid++, true, pg, vgOutput); //these numbers are in dots } - DrawGridLine((flag==0)?1:0,val,pg,pdf); + DrawGridLine((flag == 0) ? 1 : 0, val, pg, vgOutput); } } - - private void PrintText(string txt, VG.Page pg, C1PdfDocument pdf) + private void PrintText(string txt, VG.Page pg, IVGOutput vgOutput) { StringBuilder tstr = new StringBuilder(txt); -// int ptr,sptr; int ptr; SavePosition(); /* 'cause TEXT...,E screws up position! */ - ptr=0; -// sptr=0; + ptr = 0; while (ptr < tstr.Length) -// while(ptr < txt.Length) { if ("`øòó".IndexOf(tstr[ptr]) >= 0) -// if("`øòó".IndexOf(txt[ptr]) >= 0 ) { - string SpecialChar=""; -// int len = 0; - switch ( (byte)tstr[ptr]) -// switch ( (byte)txt[ptr] ) + string SpecialChar = ""; + switch ((byte)tstr[ptr]) { - case 0x60 : /* backquote */ - case 0xF8 : SpecialChar = "\u00B0"; /* degree symbol */ + case 0x60: /* backquote */ + case 0xF8: SpecialChar = "\u00B0"; /* degree symbol */ break; - case 0xF2 : SpecialChar= "\u2265"; /* greaterthanequal */ + case 0xF2: SpecialChar = "\u2265"; /* greaterthanequal */ break; - case 0xF3 : SpecialChar= "\u2264"; /* lessthanequal */ + case 0xF3: SpecialChar = "\u2264"; /* lessthanequal */ break; } - tstr.Remove(ptr,1); - tstr.Insert(ptr,SpecialChar); + tstr.Remove(ptr, 1); + tstr.Insert(ptr, SpecialChar); ptr++; -// len = txt.Substring(sptr,ptr-sptr).Length; -// GraphText( txt.Substring(sptr,ptr-sptr),pg,pdf); -// MoveRelative(len * CWIDEDOTS,0); -// sptr = ++ptr; -// GraphText(SpecialChar,pg,pdf); -// MoveRelative(CWIDEDOTS,0); - -// //!!! ADD CALLS TO OUTPUT THESE STRINGS -// MessageBox.Show("ADD CALLS TO OUTPUT SPECIAL CHARS","PrintText()"); -// // fprintf(PRT,graph_PrntStr[2]); -// // fprintf(PRT,"%c",GraphicChar&0x7F); -// // fprintf(PRT,graph_PrntStr[3]); - } - else + } + else { ptr++; } } - GraphText(tstr.ToString(),pg,pdf); -// if( ptr > sptr ) GraphText( txt.Substring(sptr,ptr-sptr),pg,pdf); + GraphText(tstr.ToString(), pg, vgOutput); RecallPosition(); } - - private void FreeBoxList() + private void FreeBoxList() { AllBoxes.Clear(); } - - private void FreeLineList() + private void FreeLineList() { AllPlots.Clear(); } - -// void FreePointList(PointList ptr) -// { -// PointListArray.Clear(); -// // struct PointList *bptr,*nptr; -// // bptr=ptr; -// // while(bptr) -// // { -// // nptr=bptr->NextPoint; -// // Zfree(&bptr->APoint); -// // Zfree(&bptr); -// // bptr=nptr; -// // } -// } - - private void Init_Graphic_Vars() + private void Init_Graphic_Vars() { int i; SavedX = new int[MAX_XY_STACK]; SavedY = new int[MAX_XY_STACK]; - LinesUsed=0; /* Number lines used by graph, in dots */ - Visible=1; + LinesUsed = 0; /* Number lines used by graph, in dots */ + Visible = 1; ShadowFlag = 0; - // _setmem(valuestring,100,'\0'); - // _setmem(powerstring,100,'\0'); CurPenWidth = 0; DrawDirection = -1; AxisTitles[X] = null; AxisTitles[Y] = null; AxisLabel[0] = 1; AxisLabel[1] = 1; - EndFlag=0; - for (i=0;i -1) + if ((tidx = txt.IndexOf(SuperScript[0], idx)) > -1) { // print text up to the superscript - tstr = txt.Substring(sidx,tidx-sidx); - drawText = new VG_Text(Xpos,Ypos,(int)FontPitch,tstr,"Letter Gothic","","","",pg); - drawText.ToPdf(pdf); - Xpos+= (CWIDEDOTS * tstr.Length); - tidx+= SuperScript[0].Length; + tstr = txt.Substring(sidx, tidx - sidx); + drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); + Xpos += (CWIDEDOTS * tstr.Length); + tidx += SuperScript[0].Length; idx = tidx; sidx = idx; - tidx = txt.IndexOf(SuperScript[1],idx); + tidx = txt.IndexOf(SuperScript[1], idx); if (tidx > 0) { // switch font pitch, move up some, and print the superscript text - tstr = txt.Substring(sidx,tidx - sidx); -// Xpos+= (CWIDEDOTS * tstr.Length); + tstr = txt.Substring(sidx, tidx - sidx); Ypos -= (CHIGHDOTS / 2); // move up half a char heigth - drawText = new VG_Text(Xpos,Ypos,(int)(FontPitch/2),tstr,"Letter Gothic","","","",pg); - drawText.ToPdf(pdf); + drawText = new VG_Text(Xpos, Ypos, (int)(FontPitch / 2), tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); Ypos += (CHIGHDOTS / 2); // move back down - Xpos += ((CWIDEDOTS/2) * tstr.Length); // positon half the width of the string + Xpos += ((CWIDEDOTS / 2) * tstr.Length); // positon half the width of the string tidx += SuperScript[1].Length; idx = tidx; sidx = idx; continue; // go back to beginning of while loop } } - else if ((tidx = txt.IndexOf(SubScript[0],idx)) > -1) + else if ((tidx = txt.IndexOf(SubScript[0], idx)) > -1) { // print text up to the superscript - tstr = txt.Substring(sidx,tidx-sidx); - drawText = new VG_Text(Xpos,Ypos,(int)FontPitch,tstr,"Letter Gothic","","","",pg); - drawText.ToPdf(pdf); - Xpos+= (CWIDEDOTS * tstr.Length); - tidx+= SubScript[0].Length; - idx=tidx; + tstr = txt.Substring(sidx, tidx - sidx); + drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); + Xpos += (CWIDEDOTS * tstr.Length); + tidx += SubScript[0].Length; + idx = tidx; sidx = idx; - tidx = txt.IndexOf(SubScript[1],idx); + tidx = txt.IndexOf(SubScript[1], idx); if (tidx > 0) { // switch font pitch, move up some, and print the superscript text - tstr = txt.Substring(sidx,tidx - sidx); -// Xpos+= (CWIDEDOTS * tstr.Length); -// Ypos += (CHIGHDOTS / 2); // move down half a char heigth - drawText = new VG_Text(Xpos,Ypos,(int)(FontPitch/2),tstr,"Letter Gothic","","","",pg); - drawText.ToPdf(pdf); -// Ypos -= (CHIGHDOTS / 2); // move back up - Xpos += ((CWIDEDOTS/2) * tstr.Length); // positon half the width of the string + tstr = txt.Substring(sidx, tidx - sidx); + drawText = new VG_Text(Xpos, Ypos, (int)(FontPitch / 2), tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); + Xpos += ((CWIDEDOTS / 2) * tstr.Length); // positon half the width of the string tidx += SubScript[1].Length; idx = tidx; sidx = idx; @@ -2152,71 +1781,27 @@ namespace XYPlots if (sidx < txt.Length) { tstr = txt.Substring(sidx); - drawText = new VG_Text(Xpos,Ypos,(int)FontPitch,tstr,"Letter Gothic","","","",pg); - drawText.ToPdf(pdf); + drawText = new VG_Text(Xpos, Ypos, (int)FontPitch, tstr, MyFontFamily, "", "", "", pg); + drawText.Draw(vgOutput); } } - - -// public XYPlot() -// { -// // -// // TODO: Add constructor logic here -// // -// AxisLabel[0] = 1; -// AxisLabel[1] = 1; -// } - - private void CreatePDFFileName(string fname) - { - int idx = fname.LastIndexOf('.'); - if (idx > 0) - _ThePDFFile = fname.Substring(0, idx) + ".pdf"; - else - _ThePDFFile = fname + ".pdf"; - } - /// - /// Generates a PDF files containing an X/Y PLot generated from the passed in + /// Generates a vgOutput files containing an X/Y PLot generated from the passed in /// commands. /// /// Plot Commands - /// Resulting PDF file - public XYPlot(string PlotCommands, string PdfFileName) + public XYPlot(string PlotCommands) { LoadBuffFromString(PlotCommands); - _ThePDFFile = PdfFileName; - ProcessXYPlot(); + Setup(); + VG.VG_Arc.iColor = 0; } - - /// - /// Generates a PDF files containing an X/Y PLot generated from the passed in - /// commands. The extension of the passed in file name (fname) will be replaced - /// with a ".pdf" of which is where the resulting graph will be placed. This - /// file name can be gotten from the "ThePDFFile" property of this class. - /// - /// File containing the X/Y plot commands - public XYPlot(string fname) - { - LoadBuff(fname); - CreatePDFFileName(fname); - ProcessXYPlot(); - } - - - public void ProcessXYPlot(/*string fname, string PdfFileName*/) + public void Setup() { char Command, PrevCommand = ' '; Init_Graphic_Vars(); - //LoadBuff(fname); FixBuffIfNeeded(); GetScaleInfo(); - - C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument(); - pdf.FontType = C1.C1Pdf.FontTypeEnum.Embedded; // embed fonts - - VG.Page pg = new Page(true,(float)(1440),(float)(1440)); - while ((Command = char.ToUpper(getchr())) != '\0') { LineDiv = 0; @@ -2224,69 +1809,86 @@ namespace XYPlots ShadowFlag = 0; switch (Command) { - case 'T': - ShadowFlag+=2; // 2 for no box + case 'T': + ShadowFlag += 2; // 2 for no box GetBoxParameters(); break; - case 'W': + case 'W': ShadowFlag++; // 1 for shadow box GetBoxParameters(); break; - case 'B': + case 'B': GetBoxParameters(); // 0 for box break; - case 'D': + case 'D': LineDiv = getint(); LineFlag = STRAIGHT; GetLineParameters(); break; - case 'L': + case 'L': LineFlag = STRAIGHT; GetLineParameters(); break; - case 'C': + case 'C': GetLineParameters(); break; - case 'X': + case 'X': GetAxisTitle(X); break; - case 'Y': + case 'Y': GetAxisTitle(Y); break; - case 'Z': + case 'Z': YLandScape = 1; YTitleOrigin = GetPair(USER); GetAxisTitle(Y); break; - case 'A': + case 'A': AxisLabel[0] = getint(); AxisLabel[1] = getint(); break; default: if (PrevCommand.Equals(null)) - MessageBox.Show("Check the first line of the X/Y Plot definition.","Unrecognized Graph Command"); + MessageBox.Show("Check the first line of the X/Y Plot definition.", "Unrecognized Graph Command"); else - MessageBox.Show(string.Format("Problem with the X/Y Plot Command after {0}",PrevCommand.ToString()),"Unrecognized Graph Command"); - // sprintf(LineBuff,"Unrecognized Graph Command: '%c'",command); - // err_exit(LineBuff,0); + MessageBox.Show(string.Format("Problem with the X/Y Plot Command after {0}", PrevCommand.ToString()), "Unrecognized Graph Command"); break; } PrevCommand = Command; } - //Graphics(1); - GenerateGrid(pg,pdf); - DoAxisTitles(pg,pdf); - DoBoxes(pg,pdf); - DrawLines(pg,pdf); - //Graphics(0); - pdf.Save(_ThePDFFile); - //c1pdf.Save(PdfFileName); + } + public void Process(IVGOutput vgOutput) + { + VG.Page pg = new Page(true, _LeftMargin, _TopMargin, _RightMargin, _BottomMargin); + GenerateGrid(pg, vgOutput); + DoAxisTitles(pg, vgOutput); + DoBoxes(pg, vgOutput); + DrawLines(pg, vgOutput); FreeBoxList(); FreeLineList(); - CloseGraph(); -// return(LinesUsed); + } + private void ShowPoints(DataPoints dataPoints) + { +#if DEBUG + foreach (DataPoint pl in dataPoints) + { + DebugOutput("x={0},y={1},slope={2}", pl.APoint.xyValue[0], pl.APoint.xyValue[1], pl.slope); + } +#endif + } + public static string Key = ""; + private void DebugOutput(string format, params object[] args) + { +#if DEBUG + //if (args.Length == 0) + // Console.WriteLine("'{0}','{1}'",Key,format); + //Console.WriteLine(format, args); +#endif + } + private void DebugShowLocation(string command) + { + //Console.WriteLine("'{0}',{1},{2}", command, Position[X], Position[Y]); } } - -} +} \ No newline at end of file diff --git a/PROMS/XYPlots/frmXYPlot.cs b/PROMS/XYPlots/frmXYPlot.cs new file mode 100644 index 00000000..4ec77b7e --- /dev/null +++ b/PROMS/XYPlots/frmXYPlot.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Drawing.Printing; +using System.Drawing.Imaging; +using System.Text; +using System.Windows.Forms; +using System.Diagnostics; +using System.IO; +using VG; +using XYPlots; + +namespace XYPlots +{ + public partial class frmXYPlot : Form + { + private string _XYPlot; + private string _Title; + public frmXYPlot(string title,string xyPlot) + { + InitializeComponent(); + _XYPlot =xyPlot; + _Title = title; + } + private void pnl_Paint(object sender, PaintEventArgs e) + { + e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; + XYPlots.XYPlot myPlot = new XYPlots.XYPlot(_XYPlot); + myPlot.SetMargins(.75F, .5F, .25F, .75F); + float scaleX = pnl.Width / myPlot.Width; + float scaleY = pnl.Height / myPlot.Height; + float scale = scaleX > scaleY ? scaleY : scaleX; + e.Graphics.ScaleTransform(scale, scale); + myPlot.Process(new VGOut_Graphics(e.Graphics)); + } + private void pnl_Resize(object sender, EventArgs e) + { + pnl.Invalidate(); + } + private void frmXYPlot_Load(object sender, EventArgs e) + { + Text = _Title; + XYPlots.XYPlot myPlot = new XYPlots.XYPlot(_XYPlot); + myPlot.SetMargins(.75F, .5F, .25F, .75F); + float scaleX = pnl.Width / myPlot.Width; + float scaleY = pnl.Height / myPlot.Height; + float scale = scaleX > scaleY ? scaleY : scaleX; + int height = (int)(Height - pnl.Height + pnl.Height * scale / scaleY); + int width = (int)(Width - pnl.Width + pnl.Width * scale / scaleX); + Size = new Size(width, height); + } + } +} \ No newline at end of file diff --git a/PROMS/XYPlots/frmXYPlot.designer.cs b/PROMS/XYPlots/frmXYPlot.designer.cs new file mode 100644 index 00000000..84958a10 --- /dev/null +++ b/PROMS/XYPlots/frmXYPlot.designer.cs @@ -0,0 +1,61 @@ +namespace XYPlots +{ + partial class frmXYPlot + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pnl = new System.Windows.Forms.Panel(); + this.SuspendLayout(); + // + // pnl + // + this.pnl.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnl.Location = new System.Drawing.Point(0, 0); + this.pnl.Name = "pnl"; + this.pnl.Size = new System.Drawing.Size(818, 702); + this.pnl.TabIndex = 1; + this.pnl.Paint += new System.Windows.Forms.PaintEventHandler(this.pnl_Paint); + this.pnl.Resize += new System.EventHandler(this.pnl_Resize); + // + // frmXYPlot + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(818, 702); + this.Controls.Add(this.pnl); + this.Name = "frmXYPlot"; + this.Text = "frmXYPlot"; + this.Load += new System.EventHandler(this.frmXYPlot_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel pnl; + } +} \ No newline at end of file diff --git a/PROMS/XYPlots/frmXYPlot.resx b/PROMS/XYPlots/frmXYPlot.resx new file mode 100644 index 00000000..19dc0dd8 --- /dev/null +++ b/PROMS/XYPlots/frmXYPlot.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file