コード例 #1
0
        void offset_sub_string()
        {
            CLabtype lab;
            CModType mod = null;
            CStgType stg;
            CPTStype pts;
            CTXTtype txt;

            short  ok;
            double chkchn1;    //, chkchn2;
            int    ichn1, chkchn_flag;


            ok  = 0;
            ind = 0;
            //rep_flag=0;


            double r9;

            r9 = 57.29577951;

            //while(! feof(fp1))
            for (int iPos = 0; iPos < listmodelfilOld.Count; iPos++)
            {
                lab   = listmodelfilOld[iPos];
                label = lab.attr;

                if (label == CLabtype.Type.Model)
                {
                    mod = (CModType)lab.Tag;
                    ok  = 0;
                }
                else if (label == CLabtype.Type.String)
                {
                    stg = (CStgType)lab.Tag;
                    if (refmod.ToLower() == mod.name.ToLower() && refstr.ToLower() == stg.label.ToLower())
                    {
                        ok = 1;
                    }
                }
                else if (label == CLabtype.Type.Point)
                {
                    pts = (CPTStype)lab.Tag;
                    val = pts.mc;

                    if (ok > 0 && ch1 <= pts.mc && pts.mc <= ch2)
                    {
                        ok = 2;

                        chn2 = pts.mc;
                        x2   = pts.mx;
                        y2   = pts.my;
                        z2   = pts.mz;

                        chndiff = Math.Abs(chn2 - chn1);

                        chkchn_flag = 0;
                        chkchn1     = chn2 / 5.0;
                        ichn1       = (int)chkchn1;
                        ichn1       = (int)(ichn1 * 5.0);

                        if (chn2 != ichn1)
                        {
                            chkchn_flag = 1;
                            if (chn2 < ch2 && chndiff < last_chndiff)
                            {
                                continue;
                            }
                        }
                        //fgetpos(fp1, &loc1);

                        if (ind == 0)
                        {
                            chn1 = chn2;
                            x1   = x2;
                            y1   = y2;
                            z1   = z2;

                            lab = listmodelfilOld[iPos + 1];
                            pts = (CPTStype)lab.Tag;
                            //fread(&lab, sizeof(char), sizeof(lab), fp1);
                            //fread(&pts, sizeof(char), sizeof(pts), fp1);

                            chn2 = pts.mc;
                            x2   = pts.mx;
                            y2   = pts.my;
                            z2   = pts.mz;

                            bearing();

                            chn2 = chn1;
                            x2   = x1;
                            y2   = y1;
                            z2   = z1;

                            //fsetpos(fp1, &loc1);
                        }
                        else
                        {
                            bearing();
                        }

                        if (type == 1)
                        {
                            ho = ho1 + (chn2 - ch1) * (ho2 - ho1) / (ch2 - ch1);
                            vo = vo1 + (chn2 - ch1) * (vo2 - vo1) / (ch2 - ch1);

                            ochn = chn2;


                            if (chn2 == chn1 && ind == 1)                       // Sandipan 28/09/2007
                            {
                                ox = last_ox;
                                oy = last_oy;
                                oz = last_oz;
                            }
                            else
                            {
                                ox      = x2 + ho * Math.Cos((brg) / r9);
                                oy      = y2 - ho * Math.Sin((brg) / r9);
                                oz      = z2 + vo;
                                last_ox = ox;
                                last_oy = oy;
                                last_oz = oz;
                            }


                            write_offset_string();
                            //fsetpos(fp1, &loc1);
                        }
                        else if (type == 2)
                        {
                            ho = ho1 + (chn2 - ch1) * (ho2 - ho1) / (ch2 - ch1);
                            se = se1 + (chn2 - ch1) * (se2 - se1) / (ch2 - ch1);
                            vo = Math.Abs(ho) * se / 100.0;

                            ochn = chn2;

                            if (chn2 == chn1 && ind == 1)                       // Sandipan 28/09/2007
                            {
                                ox = last_ox;
                                oy = last_oy;
                                oz = last_oz;
                            }
                            else
                            {
                                ox      = x2 + ho * Math.Cos((brg) / r9);
                                oy      = y2 - ho * Math.Sin((brg) / r9);
                                oz      = z2 + vo;
                                last_ox = ox;
                                last_oy = oy;
                                last_oz = oz;
                            }

                            write_offset_string();
                            //fsetpos(fp1, &loc1);
                        }
                        else if (type == 3)
                        {
                            //Do nothing
                        }

                        if (chkchn_flag == 0)
                        {
                            last_chndiff = chn2 - chn1;
                            ind          = 1;
                            chn1         = chn2;
                            x1           = x2;
                            y1           = y2;
                            z1           = z2;
                        }
                    }   //ok==1
                }       //103
                else if (label == CLabtype.Type.Text)
                {
                    txt = (CTXTtype)lab.Tag;
                }
                else if (label == CLabtype.Type.EndCode)
                {
                    if (ochn == ch2 && ok == 2)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            if (ok == 2)
            {
                lab      = new CLabtype();
                lab.attr = CLabtype.Type.EndCode;
                listmodelfilNew.Add(lab);

                //fwrite(&lab, sizeof(char), sizeof(lab), fp1);
                ok = 0;
            }
        }
コード例 #2
0
        void master_sub_string()
        {
            CLabtype lab;
            CModType mod = null;
            CStgType stg;
            CPTStype pts;
            CTXTtype txt;

            // Redeveloped Sandipan 23/03/2007
            // Redeveloped  14/06/2004
            // Redeveloped by Sandipan 04 & 05/12/2003

            //rewind(fp1);

            double[] rchn = new double[10000];
            double[] rx = new double[10000];
            double[] ry = new double[10000];
            double[] rz = new double[10000];
            double[] schn = new double[10000];
            double[] sx = new double[10000];
            double[] sy = new double[10000];
            double[] sz = new double[10000];
            int      i, j;
            int      totref;
            int      totsub;
            //string substrFile;

            double valrc, valrx, valry, valrz;
            double valsc1, valsx1, valsy1, valsz1;
            double valsc2, valsx2, valsy2, valsz2;
            //double ic, valix, valiy, valiz;
            double m1, m2, c1, c2;
            double x4, y4, z4, d, id1, id2, id3;
            double xdiff1, ydiff1, xdiff2, ydiff2, B1 = 0, B2 = 0, theta, r9, ichn, checkd;
            int    direction;
            string curmod = string.Empty, curstr;

            StreamWriter ftmp;

            try
            {
                ftmp = new StreamWriter(Path.Combine(path, "SUBSTR.TMP"), true);
            }
            catch
            {
                msgstr = "Failed to write display file " + Path.Combine(path, "SCROLL.TMP");
                error_msg();
                return;
            }

            //FILE *ftmp;
            //strcpy(substrFile, path);
            //strcat(substrFile, "\\substr.tmp");

            //if((ftmp=fopen(substrFile, "w")) == NULL)
            //{
            //    fclose(fp1);
            //    sprintf(msgstr, "Failed to open file %s", substrFile);
            //    error_msg();
            //}

            i  = 0; j = 0;
            r9 = 57.29577951;

            for (int iPos = 0; iPos < listmodelfilOld.Count; iPos++)
            {
                lab = listmodelfilOld[iPos];
                // model file for offset string
                label = lab.attr;


                if (label == CLabtype.Type.Model)
                {
                    mod  = (CModType)lab.Tag;
                    str1 = mod.name;
                    ok1  = 0;
                    ok2  = 0;
                }
                else if (label == CLabtype.Type.String)
                {
                    stg  = (CStgType)lab.Tag;
                    str2 = stg.label;

                    if (refmod.ToLower() == str1.ToLower() && refstr.ToLower() == str2.ToLower())
                    {
                        ok1 = 1;
                    }
                    else if (submod.ToLower() == str1.ToLower() && substr.ToLower() == str2.ToLower())
                    {
                        ok2      = 1;
                        ss_found = 1;
                    }
                }
                else if (label == CLabtype.Type.Point)
                {
                    pts = (CPTStype)lab.Tag;
                    if (ok1 == 1)
                    {
                        rchn[i] = pts.mc;
                        rx[i]   = pts.mx;
                        ry[i]   = pts.my;
                        rz[i]   = pts.mz;
                        i++;
                    }
                    else if (ok2 == 1)
                    {
                        schn[j] = pts.mc;
                        sx[j]   = pts.mx;
                        sy[j]   = pts.my;
                        sz[j]   = pts.mz;
                        j++;
                    }
                }
                else if (label == CLabtype.Type.Text)
                {
                    txt = (CTXTtype)lab.Tag;
                    //fread(&txt, sizeof(char), sizeof(txt), fp1);
                }
                else if (label == CLabtype.Type.EndCode)
                {
                    continue;
                }
            }   // while ! feof

            totref = i;
            totsub = j;

            if (ss_found == 0)
            {
                return;
            }

            for (i = 0; i < totref; i++)
            {
                valrc = rchn[i];
                valrx = rx[i]; valry = ry[i]; valrz = rz[i];

                for (j = 1; j < totsub; j++)
                {
                    valsc1 = schn[j - 1];
                    valsx1 = sx[j - 1]; valsy1 = sy[j - 1]; valsz1 = sz[j - 1];
                    valsc2 = schn[j];
                    valsx2 = sx[j]; valsy2 = sy[j]; valsz2 = sz[j];

                    if (valsc1 == valsc2)
                    {
                        continue;
                    }

                    xdiff1 = Math.Abs(sx[j] - sx[j - 1]);
                    if (xdiff1 == 0.0)
                    {
                        xdiff1 = 0.001;
                    }

                    ydiff1 = Math.Abs(sy[j] - sy[j - 1]);
                    if (ydiff1 == 0.0)
                    {
                        ydiff1 = 0.001;
                    }


                    m1 = (sy[j] - sy[j - 1]) / (sx[j] - sx[j - 1]);
                    c1 = sy[j - 1] - ((sy[j] - sy[j - 1]) / (sx[j] - sx[j - 1])) * sx[j - 1];
                    m2 = 0.0 - (1 / m1);
                    c2 = ry[i] - m2 * rx[i];
                    x4 = (c2 - c1) / (m1 - m2);
                    y4 = m1 * x4 + c1;

                    id1    = Math.Sqrt((x4 - sx[j - 1]) * (x4 - sx[j - 1]) + (y4 - sy[j - 1]) * (y4 - sy[j - 1]));
                    id2    = Math.Sqrt((x4 - sx[j]) * (x4 - sx[j]) + (y4 - sy[j]) * (y4 - sy[j]));
                    id3    = Math.Sqrt((sx[j - 1] - sx[j]) * (sx[j - 1] - sx[j]) + (sy[j - 1] - sy[j]) * (sy[j - 1] - sy[j]));
                    checkd = Math.Abs(id1 + id2 - id3);

                    if (checkd > 0.001)
                    {
                        continue;
                    }

                    d = Math.Sqrt((rx[i] - x4) * (rx[i] - x4) + (ry[i] - y4) * (ry[i] - y4));


                    ////
                    theta = Math.Atan(ydiff1 / xdiff1);
                    theta = Math.Abs(theta * r9);

                    if (sx[j] >= sx[j - 1] && sy[j] >= sy[j - 1])
                    {
                        B1 = 90 - theta;
                    }
                    else if (sx[j] >= sx[j - 1] && sy[j] <= sy[j - 1])
                    {
                        B1 = 90 + theta;
                    }
                    else if (sx[j] <= sx[j - 1] && sy[j] <= sy[j - 1])
                    {
                        B1 = 270 - theta;
                    }
                    else if (sx[j] <= sx[j - 1] && sy[j] >= sy[j - 1])
                    {
                        B1 = 270 + theta;
                    }

                    if (B1 < 0.0)
                    {
                        B1 = B1 + 360;
                    }
                    if (B1 > 360)
                    {
                        B1 = B1 - 360;
                    }

                    xdiff2 = Math.Abs(rx[i] - x4);
                    if (xdiff2 == 0.0)
                    {
                        xdiff2 = 0.001;
                    }

                    ydiff2 = Math.Abs(ry[i] - y4);
                    if (ydiff2 == 0.0)
                    {
                        ydiff2 = 0.001;
                    }

                    theta = Math.Atan(ydiff2 / xdiff2);
                    theta = Math.Abs(theta * r9);

                    if (rx[i] >= x4 && ry[i] >= y4)
                    {
                        B2 = 90 - theta;
                    }
                    else if (rx[i] >= x4 && ry[i] <= y4)
                    {
                        B2 = 90 + theta;
                    }
                    else if (rx[i] <= x4 && ry[i] <= y4)
                    {
                        B2 = 270 - theta;
                    }
                    else if (rx[i] <= x4 && ry[i] >= y4)
                    {
                        B2 = 270 + theta;
                    }

                    if (B2 < 0.0)
                    {
                        B2 = B2 + 360;
                    }
                    if (B2 > 360)
                    {
                        B2 = B2 - 360;
                    }


                    // Ref Halignrep.cpp
                    // determine Actual direction of Turn
                    // 16/01/2003	Sandipan
                    // 30/05/2003	Sandipan
                    // 31/07/2003	Sandipan
                    // 17/08/2003	Sandipan
                    // Opened & modified on 10/02/2004  on Constell's Meghalaya work, Sandipan


                    if (B2 > B1)
                    {
                        if (0 <= B1 && B1 <= 90 && 270 <= B2 && B2 <= 360)
                        {
                            direction = 1;
                        }
                        else if (0 <= B1 && B1 <= 90 && 180 <= B2 && B2 <= 270)
                        {
                            if (B2 > B1 + 180)
                            {
                                direction = 1;
                            }
                            else
                            {
                                direction = 2;
                            }
                        }

                        else if (90 <= B1 && B1 <= 180 && 270 <= B2 && B2 <= 360)
                        {
                            if (B2 > B1 + 180)
                            {
                                direction = 1;
                            }
                            else
                            {
                                direction = 2;
                            }
                        }

                        else
                        {
                            direction = 2;
                        }
                    }
                    else
                    {
                        if (270 <= B1 && B1 <= 360 && 0 <= B2 && B2 <= 90)
                        {
                            direction = 2;
                        }
                        else if (180 <= B1 && B1 <= 270 && 0 <= B2 && B2 <= 90)
                        {
                            if (B1 > B2 + 180)
                            {
                                direction = 2;
                            }
                            else
                            {
                                direction = 1;
                            }
                        }
                        else if (270 <= B1 && B1 <= 360 && 90 <= B2 && B2 <= 180)
                        {
                            if (B1 > B2 + 180)
                            {
                                direction = 2;
                            }
                            else
                            {
                                direction = 1;
                            }
                        }
                        else
                        {
                            direction = 1;
                        }
                    }

                    // Done for halignrep.cpp on 10/02/2004  Sandipan

                    if (direction == 1)
                    {
                        sign_d = 1;
                    }
                    else if (direction == 2)
                    {
                        sign_d = -1;
                    }

                    ichn = schn[j - 1] + Math.Sqrt((sx[j - 1] - x4) * (sx[j - 1] - x4) + (sy[j - 1] - y4) * (sy[j - 1] - y4));
                    se   = se1 + (se2 - se1) * (ichn - ch1) / (ch2 - ch1);
                    ho   = d * sign_d;
                    vo   = Math.Abs(ho) * se / 100.0;
                    z4   = rz[i] + vo;
                    ////

                    ftmp.WriteLine(valrc.ToString() + '\t'
                                   + ichn.ToString() + '\t'
                                   + x4.ToString() + '\t'
                                   + y4.ToString() + '\t'
                                   + z4.ToString() + '\t'
                                   + ho.ToString() + '\t'
                                   + vo.ToString());
                    //ftmp.Write(string.Format("{0:f5} {1:f5} {2:f5} {3:f5} {4:f5} {5:f3} {6:f3}\n", valrc, ichn, x4, y4, z4, ho, vo));
                    //fprintf(ftmp, "%.5f %.5f %.5f %.5f %.5f %.3f %.3f\n", valrc, ichn, x4, y4, z4, ho, vo);
                    break;
                }
            }

            //fclose(fp1);
            ftmp.Close();


            for (int iPos = 0; iPos < listmodelfilOld.Count; iPos++)
            {
                lab = listmodelfilOld[iPos];
                if (label == CLabtype.Type.Model)
                {
                    mod    = (CModType)lab.Tag;
                    curmod = mod.name;
                }
                else if (label == CLabtype.Type.String)
                {
                    stg    = (CStgType)lab.Tag;
                    curstr = stg.label;

                    if (curmod.ToLower() == submod.ToLower() && curstr.ToLower() == substr.ToLower())
                    {
                        mod.name  = "";
                        stg.label = "";
                        listmodelfilOld[iPos - 1].Tag = mod;
                        listmodelfilOld[iPos].Tag     = stg;
                    }
                }
                else if (label == CLabtype.Type.Point)
                {
                    pts = (CPTStype)lab.Tag;
                }
                else if (label == CLabtype.Type.Text)
                {
                    txt = (CTXTtype)lab.Tag;
                }
            }

            StreamReader ftmpR = new StreamReader(Path.Combine(path, "SUBSTR.TMP"));

            fp5 = new StreamWriter(Path.Combine(path, "SHIFT.FIL"), false);

            StreamWriter tmpFile = null;
            int          scroll  = 1;

            try
            {
                tmpFile = new StreamWriter(Path.Combine(path, "SCROLL.TMP"), true);
            }
            catch
            {
                scroll = 0;
            }



            lab      = new CLabtype();
            lab.attr = CLabtype.Type.Model;
            mod      = new CModType();
            mod.name = submod;
            lab.Tag  = mod;
            listmodelfilNew.Add(lab);


            lab       = new CLabtype();
            lab.attr  = CLabtype.Type.String;
            stg       = new CStgType();
            stg.label = substr;
            lab.Tag   = stg;
            listmodelfilNew.Add(lab);

            while (ftmpR.EndOfStream == false)
            {
                string[] tok = ftmpR.ReadLine().Split(new char[] { '\t' });
                valrc = double.Parse(tok[0]);
                ichn  = double.Parse(tok[1]);
                x4    = double.Parse(tok[2]);
                y4    = double.Parse(tok[3]);
                z4    = double.Parse(tok[4]);
                ho    = double.Parse(tok[5]);
                vo    = double.Parse(tok[6]);
                //fscanf(ftmp, "%lf %lf %lf %lf %lf %lf %lf", &valrc, &ichn, &x4, &y4, &z4, &ho, &vo);

                lab      = new CLabtype();
                lab.attr = CLabtype.Type.Point;
                pts      = new CPTStype();
                pts.mc   = ichn;
                pts.mx   = x4;
                pts.my   = y4;
                pts.mz   = z4;
                lab.Tag  = pts;
                listmodelfilNew.Add(lab);


                //Write Report File
                fp4.Write(string.Format(" {0,10:f3}       {1,10:f5}  {2,15:f5}  {3,15:f5}  {4,10:f3} {5,8:f3} {6,8:f3}\n", valrc, ichn, x4, y4, z4, ho, vo));

                //Write Shift File
                fp5.Write(string.Format(" {0,10:f5}  {1,35:f3}\n", valrc, ho));

                //Write Display Scroll File
                if (scroll == 1)
                {
                    tmpFile.Write(string.Format("{0} {1} {2,10:f3} {3,10:f3} {4,10:f3} {5,10:f3} {6,8:f3} {7,5:f3} {8,5:f3}\n", submod, substr, valrc, ichn, x4, y4, z4, ho, vo));
                }
            }

            lab      = new CLabtype();
            lab.attr = CLabtype.Type.EndCode;
            listmodelfilNew.Add(lab);

            //fclose(fp1);
            ftmpR.Close();
            fp5.Close();
        }
コード例 #3
0
        void offset_alignment()
        {
            CLabtype.Type label = CLabtype.Type.Unknown;
            short         ok;
            double        temp;

            CLabtype lab;
            CPTStype pts = new CPTStype();
            //CTXTtype txt;
            CModType mod = null;
            CStgType stg;

            ok       = 0;
            cont_ind = 0;

            if (chn1 > chn2)
            {
                temp = chn2;
                chn2 = chn1;
                chn1 = temp;
            }

            pathfile = Path.Combine(path, "MODEL.FIL");

            if (File.Exists(pathfile) == false)
            {
                return;
            }
            List <CLabtype> listmodelfil = new List <CLabtype>();

            ViewerUtils.ReadModelFilFile(pathfile, ref listmodelfil);
            for (int iIndex = 0; iIndex < listmodelfil.Count; iIndex++)
            {
                lab   = listmodelfil[iIndex];
                label = lab.attr;

                if (label == CLabtype.Type.EndCode)
                {
                    ok = 0;
                }

                else if (label == CLabtype.Type.Model)
                {
                    mod = (CModType)lab.Tag;
                }

                else if (label == CLabtype.Type.String)
                {
                    stg = (CStgType)lab.Tag;

                    if (refmod.ToLower() == mod.name.ToLower() && refstg.ToLower() == stg.label.ToLower())
                    {
                        ok = 1;
                    }
                }
                else if (label == CLabtype.Type.Point)
                {
                    pts = (CPTStype)lab.Tag;
                    chn = pts.mc;
                    mx  = pts.mx;
                    my  = pts.my;
                    mz  = pts.mz;

                    if (ok == 1)
                    {
                        if (cont_ind == 0)
                        {
                            store_last();

                            lab = listmodelfil[iIndex + 1];
                            pts = (CPTStype)lab.Tag;


                            chn = pts.mc;
                            mx  = pts.mx;
                            my  = pts.my;
                            mz  = pts.mz;

                            //fsetpos(fp1, &loc1);
                        }

                        if (last_chn2 == chn)
                        {
                            continue;
                        }

                        if (last_x == mx)
                        {
                            mx += 0.001;
                        }

                        if (last_y == my)
                        {
                            my += 0.001;
                        }

                        if ((chn > chn1 && chn < chn2) && chn != last_chn2)
                        {
                            calc_offset();

                            write_drg();
                        }

                        if (chn >= chn2)
                        {
                            break;
                        }

                        if (cont_ind == 1)
                        {
                            store_last();
                        }

                        cont_ind = 1;
                    }   // OK=1
                }       //103
            }
            if (ok == 1)
            {
                store_last();
                chn = pts.mc + 0.001;
                mx  = pts.mx + 0.001;
                my  = pts.my + 0.001;
                mz  = pts.mz;
                calc_offset();
                write_drg();
            }
        }