Esempio n. 1
0
        //const double r9 = 57.29577951;
        public bool WriteHIPFile(string strPath, CHalFile filedata)
        {
            bool         bSuccess = false;
            BinaryWriter bw       = new BinaryWriter(new FileStream(strPath, FileMode.Create), Encoding.Default);

            if (bw != null)
            {
                short sTotalHips = (short)filedata.ListHip.Count;
                bw.Write(filedata.Code);                                                  //Line code
                bw.Write(filedata.AcceptCode);                                            //Accept code
                bw.Write(ViewerUtils.ConvertStringToByteArray(filedata.ModelName, 30));   //Model name
                bw.Write(ViewerUtils.ConvertStringToByteArray(filedata.StringLevel, 20)); //String level

                bw.Write(sTotalHips);                                                     //Total HIPs
                bw.Write(filedata.StartChainage);                                         //Start Chain
                bw.Write(filedata.ChainageInterval);                                      //Chainage Interval

                for (short iIndex = 0; iIndex < sTotalHips; iIndex++)
                {
                    CHHipData hhipObj = filedata.ListHip[iIndex];

                    short sTotalHIP = (short)(iIndex + 1);
                    bw.Write(sTotalHIP);//Hip no
                    bw.Write(hhipObj.xvalue);
                    bw.Write(hhipObj.yvalue);
                    bw.Write(hhipObj.radius);
                    bw.Write(hhipObj.leadtrans);
                    bw.Write(hhipObj.trailtrans);
                }
                bw.Close();
                bSuccess = true;
            }
            return(bSuccess);
        }
Esempio n. 2
0
        public bool ReadHIPFile(string strPath, out CHalFile filedata)
        {
            bool bSuccess = false;

            filedata = new CHalFile();
            BinaryReader br = new BinaryReader(new FileStream(strPath, FileMode.Open, FileAccess.Read), Encoding.Default);

            if (br != null)
            {
                filedata.Code        = br.ReadInt16();                                         //Line code
                filedata.AcceptCode  = br.ReadInt16();                                         //Accept code
                filedata.ModelName   = ViewerUtils.ConvertCharArrayToString(br.ReadBytes(30)); //Model name
                filedata.StringLevel = ViewerUtils.ConvertCharArrayToString(br.ReadBytes(20)); //String level

                short sTotalHIP = br.ReadInt16();                                              //Total HIPs
                filedata.StartChainage    = br.ReadDouble();                                   //Start Chain
                filedata.ChainageInterval = br.ReadDouble();                                   //Chainage Interval

                for (short sCnt = 0; sCnt < sTotalHIP; sCnt++)
                {
                    CHHipData hhipObj = new CHHipData();
                    short     iHipNo  = br.ReadInt16();
                    hhipObj.xvalue     = br.ReadDouble();
                    hhipObj.yvalue     = br.ReadDouble();
                    hhipObj.radius     = br.ReadDouble();
                    hhipObj.leadtrans  = br.ReadDouble();
                    hhipObj.trailtrans = br.ReadDouble();

                    filedata.ListHip.Add(hhipObj);
                }

                br.Close();
                bSuccess = true;
            }
            return(bSuccess);
        }
Esempio n. 3
0
        private bool hip_method()
        {
            bool bSuccess = true;

            fp1 = new BinaryReader(new FileStream(Path.Combine(this.m_strWorkingDirPath, "HAL1.tmp"), FileMode.Open, FileAccess.Read), Encoding.Default);

            CHalFile filedata = new CHalFile();

            filedata.Code        = fp1.ReadInt16();                                         //Line code
            filedata.AcceptCode  = fp1.ReadInt16();                                         //Accept code
            filedata.ModelName   = ViewerUtils.ConvertCharArrayToString(fp1.ReadBytes(30)); //Model name
            filedata.StringLevel = ViewerUtils.ConvertCharArrayToString(fp1.ReadBytes(20)); //String level
            short sTotalHIP = fp1.ReadInt16();                                              //Total HIPs

            filedata.StartChainage    = fp1.ReadDouble();                                   //Start Chain
            filedata.ChainageInterval = fp1.ReadDouble();                                   //Chainage Interval



            modnam = filedata.ModelName;
            stglbl = filedata.StringLevel;
            hips   = sTotalHIP;
            chn1   = filedata.StartChainage;
            inc    = filedata.ChainageInterval;
            ptsc   = 0;
            pts    = 0;

            fpm = new StreamWriter(Path.Combine(this.m_strWorkingDirPath, "ERRORMESSAGES.TXT"), true);
            fpm.WriteLine();
            fpm.WriteLine("    *************************************************");
            fpm.WriteLine("    Program [HEADS:Design:HALIGNMENT] was run on : " + DateTime.Now.ToString());

            for (ip = 0; ip < hips - 2; ip++)
            {
                hip_input();

                bearings();

                deflection();

                tangent_points();

                if (error_flag != 0)
                {
                    break;
                }

                if (lt1 > 0)
                {
                    elno++;
                    eltype = 1;
                    //chn1 = chn1;
                    hipx = x2;
                    hipy = y2;
                    l    = lt1;

                    if (ip == 0)
                    {
                        xs = x1;
                        ys = y1;
                    }
                    else
                    {
                        xs = xe;
                        ys = ye;
                    }
                    b1 = B1;

                    element();
                }

                if (ls1 > 0)
                {
                    elno++;
                    eltype = 2;
                    chn1   = chn2;
                    hipx   = x2;
                    hipy   = y2;
                    l      = ls1;
                    xs     = xe; ys = ye;
                    b1     = b2;

                    element();
                }


                if (lc > 0)
                {
                    elno++;
                    eltype = 3;
                    chn1   = chn2;
                    hipx   = x2;
                    hipy   = y2;
                    l      = lc;
                    xs     = xe; ys = ye;
                    b1     = b2;

                    element();
                }

                if (ls2 > 0)
                {
                    elno++;
                    eltype = 4;
                    chn1   = chn2;
                    hipx   = x2;
                    hipy   = y2;
                    l      = ls2;
                    xs     = xe; ys = ye;
                    b1     = b2;

                    element();
                }

                x1 = xe; y1 = ye;
                xm = x2; ym = y2;
                x2 = x3; y2 = y3;

                rad  = last_rad;
                ls1  = last_ls1;
                ls2  = last_ls2;
                turn = last_turn;

                chn1 = chn2;
                B1   = b2;
            }

            if (error_flag == 0)
            {
                if (lt2 > 0)
                {
                    elno++;
                    eltype = 1;
                    chn1   = chn2;
                    hipx   = xm;
                    hipy   = ym;
                    l      = lt2;
                    xs     = xe; ys = ye;
                    b1     = B2;

                    element();
                }
            }


            fpm.WriteLine("    *************************************************");
            fpm.Close();
            fp1.Close();

            if (error_flag == 1)
            {
                System.Windows.Forms.MessageBox.Show("Check the file ERRORMESSAGES.TXT for all the details", HeadsUtils.Constants.ProductName);
                bSuccess = false;
            }
            else
            {
                bSuccess = true;
            }

            return(bSuccess);
        }
Esempio n. 4
0
        private void ApplyHIP()
        {
            this.m_app.ActiveDocument.ConfigParam.XMetric = 1;
            this.m_app.ActiveDocument.ConfigParam.YMetric = 1;

            //Delete existing hip line
            IHdEntity entity = this.m_app.ActiveDocument.GetObjectById(this.m_iLastAppliedPolyLine);

            if (entity != null)
            {
                entity.Erase();
            }

            //Erase the selected polyline on screen
            //this is because user may modify the X, Y
            //co-ordinates using this dialog
            entity = this.m_app.ActiveDocument.GetObjectById(this.m_iMainPolyLine);
            if (entity != null)
            {
                List <CHHipData> listLinedata = new List <CHHipData>();
                GetPolylineDetails((IHdPolyline3D)entity, ref listLinedata);
                int temCount = this.dtParams.Rows.Count;
                for (int iCnt = 0; iCnt < temCount; iCnt++)
                {
                    CHHipData hdata = listLinedata[iCnt];

                    this.dtParams.Rows[iCnt][FormHipMethod.ColNameXValue] = hdata.xvalue;
                    this.dtParams.Rows[iCnt][FormHipMethod.ColNameYValue] = hdata.yvalue;
                }
                UpdateDeltaValue();

                entity.Erase();
            }
            //Redraw the polyline
            List <CPoint3D> listPt = new List <CPoint3D>();

            for (int iCnt = 0; iCnt < this.dtParams.Rows.Count; iCnt++)
            {
                CHHipData data = this.GetRow(iCnt);
                listPt.Add(new CPoint3D(data.xvalue, data.yvalue, 0));
            }
            this.m_iMainPolyLine = this.m_app.ActiveDocument.DrawPolyline3D(listPt).ObjectID;


            //Refresh the document
            this.m_app.ActiveDocument.RefreshDocument();


            List <CHHipData> listHips = new List <CHHipData>();

            for (int iCnt = 0; iCnt < this.dtParams.Rows.Count; iCnt++)
            {
                listHips.Add(this.GetRow(iCnt));
            }

            CHalFile filedata = new CHalFile();

            filedata.Code             = 1;
            filedata.AcceptCode       = 0;
            filedata.ModelName        = this.txtModelName_.Text.Trim();
            filedata.StringLevel      = this.txtStringlabel_.Text.Trim();
            filedata.StartChainage    = this.txtStartInterval_.Value;
            filedata.ChainageInterval = this.txtChainageInterval_.Value;
            filedata.ListHip          = listHips;

            string         strHipFilePath = Path.Combine(m_app.AppDataPath, "HAL1.tmp");
            CHalignHipUtil util           = new CHalignHipUtil();

            if (util.WriteHIPFile(strHipFilePath, filedata))
            {
                //Delete HAL2.TEMP
                string strHAL2TmpPath = Path.Combine(m_app.AppDataPath, "HAL2.tmp");
                ViewerUtils.DeleteFileIfExists(strHAL2TmpPath);

                //try
                {
                    if (util.FuncMain(this.m_app.AppDataPath) == true)
                    {
                        this.m_iLastAppliedPolyLine = DrawingUtil.DrawData(this.m_app, strHAL2TmpPath, "PVR", true);
                        this.m_app.ActiveDocument.RefreshDocument();

                        //this.m_app.ZoomExtents();
                    }
                }
                //catch (Exception ex)
                //{
                //    MessageBox.Show(this, ex.ToString(), "ERROR!"
                //        , MessageBoxButtons.OK
                //        , MessageBoxIcon.Error);
                //    System.Diagnostics.Trace.Write(ex.ToString());
                //}
            }
            else
            {
                MessageBox.Show(this
                                , "Failed to generate HIP file"
                                , Resources.ST_ERROR_MSGBOX_CAPTION
                                , MessageBoxButtons.OK
                                , MessageBoxIcon.Error);
            }

            this.ShowDetails(checkBoxShowDetails_.Checked);
        }