public void Funcmain(string argv1, CCfgtype cfg) { path = argv1; //err_code = 9; /* no error */ read_input(); pathfile = Path.Combine(path, "DETAILS2.TMP"); fp2 = new BinaryWriter(new FileStream(pathfile, FileMode.Create), Encoding.Default); if (rotn != 0.0) { textstring = "DRG not by 'Draw String', use 'Minor option(s) 1103 / 1104'..."; error_msg(); return; } pathfile = Path.Combine(path, "VALIGN.TMP"); if (File.Exists(pathfile) == false) { pathfile = Path.Combine(path, "VALIGN.FIL"); } fp1 = new StreamReader(pathfile); index = false; while (fp1.EndOfStream == false) { init_param(); des_curve_input(); if (flag == 0) { continue; } if (stchn == last_stchn && endchn == last_endchn) { break; } draw_hips(cfg); last_stchn = stchn; last_endchn = endchn; index = true; } // end while(fp1.EndOfStream == false) end_HIP(); fp1.Close(); fp2.Close(); }
void ApplyValign() { if (this.ValidateData()) { this.app.ActiveDocument.ConfigParam.XMetric = 1; this.app.ActiveDocument.ConfigParam.YMetric = 10; CCfgtype cfg = new CCfgtype(); this.app.ActiveDocument.ConfigParam.CopyTo(cfg); IHdEntity entity = this.app.ActiveDocument.GetObjectById(this.LastAppliedPolyLineID); 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.app.ActiveDocument.GetObjectById(this.MainPolyLineID); if (entity != null) { entity.Erase(); } List <VVIP> listParams = GetParamData(); List <CPoint3D> polypts = new List <CPoint3D>(); foreach (VVIP vdata in listParams) { polypts.Add(new CPoint3D(vdata.chainx * cfg.XMetric, vdata.chainy * cfg.YMetric, 0)); } this.MainPolyLineID = this.app.ActiveDocument.DrawPolyline3D(polypts).ObjectID; this.WriteDataFile(); ViewerUtils.DeleteFileIfExists(Path.Combine(this.app.AppDataPath, "VAL2.TMP")); CValignUtil util = new CValignUtil(); if (util.Funcmain(this.app.AppDataPath)) { DrawingUtil.DrawData(this.app, Path.Combine(this.app.AppDataPath, "VAL2.TMP"), "PVR", true); } this.app.ActiveDocument.RefreshDocument(); } }
private void PopulateData(CCfgtype cfgparam) { this.tbXFactor_.Text = cfgparam.XMetric.ToString(); this.tbYFactor_.Text = cfgparam.YMetric.ToString(); this.tbRotatonAngle_.Text = cfgparam.xfa.ToString(); this.tbXOrigin_.Text = cfgparam.XLate_X.ToString(); this.tbYOrigin_.Text = cfgparam.XLate_Y.ToString(); this.tbHorizontalScale_.Text = cfgparam.hs.ToString(); this.tbMarginTop_.Text = cfgparam.tm.ToString(); this.tbMarginBottom_.Text = cfgparam.bm.ToString(); this.tbMarginLeft_.Text = cfgparam.lm.ToString(); this.tbMarginRight_.Text = cfgparam.rm.ToString(); this.tbSheetLength_.Text = cfgparam.sl.ToString(); this.tbSheetWidth_.Text = cfgparam.sw.ToString(); }
void GetDataFromPolyLine(IHdPolyline3D polyline, ref List <VVIP> listVipData) { CCfgtype cfg = this.app.ActiveDocument.ConfigParam; listVipData.Clear(); if (polyline != null) { CPoint3D[] ptCords = polyline.Coordinates; for (int iIndex = 0; iIndex < ptCords.Length; iIndex++) { VVIP data = new VVIP(); data.chainx = ptCords[iIndex].X / cfg.XMetric; data.chainy = ptCords[iIndex].Y / cfg.YMetric; listVipData.Add(data); } } }
void draw_hips(CCfgtype cfg) { //zt = 0.0; textrotn = 0.0; double dVcl, dK; double dLead = 1.2; // gap between lines if (IPX != last_IPX && IPY != last_IPY) { if (index == false) // Start HIP { xt = xst - xlate_x; yt = yst - xlate_y; plan_form(ref xt, ref yt); textstring = "Start chainage / Level: " + xst.ToString("0.000") + ", " + yst.ToString("0.000") + " m."; textwrite(); } } if (eltype == 3) { xt = IPX - xlate_x; yt = IPY - xlate_y; plan_form(ref xt, ref yt); textstring = "VIP Chainage = " + IPX.ToString("0.000") + " m"; xstor = xt; ystor = yt; textwrite(); xt = xstor; yt = ystor; yt -= textsize / cfg.YMetric * dLead; textstring = "VIP Level = " + IPY.ToString("0.000") + " m"; xstor = xt; ystor = yt; textwrite(); xt = xstor; yt = ystor; yt -= textsize / cfg.YMetric * dLead; dVcl = R + L; if (Math.Abs(R - L) < 0.001) { textstring = "VCL = " + dVcl.ToString("0.000") + " m"; } else { textstring = "VCL1 = " + R.ToString("0.000") + " m, VCL2 = " + L.ToString("0.000") + " m"; } xstor = xt; ystor = yt; textwrite(); xt = xstor; yt = ystor; yt -= textsize / cfg.YMetric * dLead; textstring = "g1 = " + B1.ToString("0.000") + " %, g2 = " + B2.ToString("0.000") + " % "; xstor = xt; ystor = yt; textwrite(); yt = ystor; xt = xstor; yt -= textsize / cfg.YMetric * dLead; if (turn1 == 1) { R = 0.0 - R; } textstring = "Grade Difference = " + DEL.ToString("0.000") + " %"; xstor = xt; ystor = yt; textwrite(); xt = xstor; yt = ystor; yt -= textsize / cfg.YMetric * dLead; dK = Math.Abs(dVcl / (B2 - B1)); if (turn1 == 2) { dK *= -1; } textstring = "K = " + dK.ToString("0.000"); xstor = xt; ystor = yt; textwrite(); xt = xstor; yt = ystor; } last_IPX = IPX; last_IPY = IPY; }
void ShowItemEntities(List <CLabtype> entities, string strModelName, string stgLabel) { int NumPts = 0; CPoint3D ptStart = new CPoint3D(); CPoint3D ptEnd = new CPoint3D(); CPoint3D ptLast = new CPoint3D(); CTXTtype txt = new CTXTtype(); CLinetype uline = new CLinetype(); IHdPolyline3D polyline = null; string str1 = ""; IHdPoint aPoint = null; CPTStype pts = new CPTStype(); this.App.ActiveDocument.ConfigParam.XMetric = 1.0; this.App.ActiveDocument.ConfigParam.YMetric = 1.0; CCfgtype cfg = this.App.ActiveDocument.ConfigParam; eHEADS_COLOR entitycolor = (stgLabel.StartsWith("member")) ? FormLoadDeflection.MemberColor : FormLoadDeflection.LoadColor; double dTextHeight = (this.App.ActiveDocument.ActiveTextHeight > 0) ? this.App.ActiveDocument.ActiveTextHeight : 1.0; for (int iIndex = 0; iIndex < entities.Count; iIndex++) { CLabtype labtype = entities[iIndex]; if (labtype.attr == CLabtype.Type.Point) { pts = (CPTStype)labtype.Tag; ptEnd = new CPoint3D(pts.mx * cfg.XMetric, pts.my * cfg.YMetric, pts.mz); NumPts++; ptStart = ptLast; ptLast = ptEnd; uline.StartPoint = new CPoint3D(ptStart); uline.EndPoint = new CPoint3D(ptEnd); str1 = stgLabel; if (NumPts == 1) { aPoint = this.App.ActiveDocument.DrawPoint(ptEnd); aPoint.color = entitycolor; } else if (NumPts == 2) { uline.Layer = this.App.ActiveDocument.GetActiveLayer().Name; uline.elatt = 1; uline.laatt = 1; uline.Label = strModelName; uline.Label += ":"; uline.Label += stgLabel; uline.scatt = 1; polyline = DrawingUtil.DrawPolyline3DDx(this.App.ActiveDocument, true, uline); polyline.color = entitycolor; aPoint.Erase(); } else if (NumPts > 2) { polyline.AppendVertex(ptEnd); } } else if (labtype.attr == CLabtype.Type.Text) { txt = (CTXTtype)labtype.Tag; ptEnd = new CPoint3D(txt.tx * cfg.XMetric, txt.ty * cfg.YMetric, txt.tz); str1 = txt.tg; IHdText textobj = this.App.ActiveDocument.DrawText(ptEnd, str1, dTextHeight); textobj.color = entitycolor; aPoint = this.App.ActiveDocument.DrawPoint(ptEnd); aPoint.color = entitycolor; } else if (labtype.attr == CLabtype.Type.EndCode) { NumPts = 0; } } this.App.ActiveDocument.RefreshDocument(true); }
public static void ExportToDRG(IHeadsApplication app, string strPath) { CCfgtype cfg = app.ActiveDocument.ConfigParam; CBox box = app.ActiveDocument.BoundingBox; double[] Arr = new double[] { box.BottomRight.X, box.BottomRight.Y, box.TopLeft.X, box.TopLeft.Y }; cfg.XLate_X = Arr[0]; cfg.XLate_Y = Arr[1]; cfg.hs = (297 / (Arr[2] - cfg.XLate_X)); BinaryWriter bw = new BinaryWriter(new FileStream(strPath, FileMode.Create), Encoding.Default); Eldtype eld = new Eldtype(); eld.Code = 99; bw.Write(eld.Code); cfg.ToStream(bw); IHdEntity[] allEntities = app.ActiveDocument.Entities; foreach (IHdEntity entity in allEntities) { if (entity.EntityName == "LINE") { IHdLine hdline = (IHdLine)entity; eld.Code = (short)((Constants.BuildType == eHEADS_RELEASE_TYPE.DEMO) ? 91 : 1); bw.Write(eld.Code); Linetype line = new Linetype(); line.elatt = 0; line.scatt = 1; line.layer = hdline.Layer; line.laatt = 1; line.x1 = hdline.StartPoint.X; line.y1 = hdline.StartPoint.Y; line.z1 = hdline.StartPoint.Z; line.x1 = line.x1 / cfg.XMetric; line.y1 = line.y1 / cfg.YMetric; line.x2 = hdline.EndPoint.X; line.y2 = hdline.EndPoint.Y; line.z2 = hdline.EndPoint.Z; line.x2 = line.x2 / cfg.XMetric; line.y2 = line.y2 / cfg.YMetric; line.color = entity.ColorIndex; if (hdline.Label == "") { line.label = "$$$$$$$$:****"; } else { line.label = hdline.Label; } line.ToStream(bw); } else if (entity.EntityName == "ELLIPSE") { IHdEllipse hdEllipse = (IHdEllipse)entity; eld.Code = (short)((Constants.BuildType == eHEADS_RELEASE_TYPE.DEMO) ? 93 : 3); bw.Write(eld.Code); Circletype circle1 = new Circletype(); circle1.elatt = 0; circle1.scatt = 1; circle1.Layer = hdEllipse.Layer; circle1.laatt = 1; circle1.xc = hdEllipse.CenterPoint.X; circle1.yc = hdEllipse.CenterPoint.Y; circle1.xc = circle1.xc / cfg.XMetric; circle1.yc = circle1.yc / cfg.YMetric; circle1.Radius = hdEllipse.Radius; circle1.color = entity.ColorIndex; if (hdEllipse.Label == "") { circle1.Label = "$$$$$$$$:****"; } else { circle1.Label = hdEllipse.Label; } circle1.ToStream(bw); } else if (entity.EntityName == "ARC") { IHdArc hdArc = (IHdArc)entity; eld.Code = (short)((Constants.BuildType == eHEADS_RELEASE_TYPE.DEMO) ? 94 : 4); bw.Write(eld.Code); Arctype arc = new Arctype(); arc.elatt = 0; arc.scatt = 1; arc.Layer = hdArc.Layer; arc.laatt = 1; arc.xc = hdArc.CenterPoint.X; arc.yc = hdArc.CenterPoint.Y; arc.xc = arc.xc / cfg.XMetric; arc.yc = arc.yc / cfg.YMetric; arc.xs = (arc.xc + hdArc.Radius * Math.Cos(hdArc.StartAngle)) / cfg.XMetric; arc.ys = (arc.yc + hdArc.Radius * Math.Sin(hdArc.StartAngle)) / cfg.YMetric; arc.xe = (arc.xc + hdArc.Radius * Math.Cos(hdArc.EndAngle)) / cfg.XMetric; arc.ye = (arc.yc + hdArc.Radius * Math.Sin(hdArc.EndAngle)) / cfg.YMetric; arc.Radius = hdArc.Radius; arc.Color = entity.ColorIndex; if (hdArc.Label == "") { arc.Label = "$$$$$$$$:****"; } else { arc.Label = hdArc.Label; } arc.ToStream(bw); } else if (entity.EntityName == "POLYLINE3D") { IHdPolyline3D hdPline = (IHdPolyline3D)entity; CPoint3D[] Coord = hdPline.Coordinates; int NumVerticies = Coord.Length - 2; for (int j = 0; j <= NumVerticies; j++) { eld.Code = (short)((Constants.BuildType == eHEADS_RELEASE_TYPE.DEMO) ? 91 : 1); bw.Write(eld.Code); Linetype line = new Linetype(); if (j == 0) { line.elatt = 0; } else { line.elatt = 1; } //line.elatt = X; line.scatt = 1; line.layer = hdPline.Layer; line.laatt = 1; line.x1 = Coord[j].X; line.y1 = Coord[j].Y; line.z1 = Coord[j].Z; line.x1 = line.x1 / cfg.XMetric; line.y1 = line.y1 / cfg.YMetric; line.x2 = Coord[j + 1].X; line.y2 = Coord[j + 1].Y; line.z2 = Coord[j + 1].Z; line.x2 = line.x2 / cfg.XMetric; line.y2 = line.y2 / cfg.YMetric; line.color = entity.ColorIndex; if (hdPline.Label == "") { line.label = "$$$$$$$$:****"; } else { line.label = hdPline.Label; } line.ToStream(bw); } } else if (entity.EntityName == "TEXT") { IHdText hdTxt = (IHdText)entity; eld.Code = (short)((Constants.BuildType == eHEADS_RELEASE_TYPE.DEMO) ? 90 : 9); bw.Write(eld.Code); TEXTtype text = new TEXTtype(); text.Length = 1; text.scatt = 1; text.Layer = hdTxt.Layer; text.laatt = 1; text.x1 = hdTxt.InsertionPoint.X; text.y1 = hdTxt.InsertionPoint.Y; text.x1 = text.x1 / cfg.XMetric; text.y1 = text.y1 / cfg.YMetric; text.Size = hdTxt.Height; text.rotn = hdTxt.Rotation * 180 / Math.PI; text.text = hdTxt.Text; text.Color = entity.ColorIndex; if (hdTxt.Label == "") { text.Label = "$$$$$$$$:****"; } else { text.Label = hdTxt.Label; } text.ToStream(bw); } } bw.Close(); }
public static void DrawDrg(IHeadsApplication app, string szFileName, string sType, bool bEngFunc) { if (File.Exists(szFileName) == false) { return; } Eldtype eld = new Eldtype(); Linetype line = new Linetype(); Boxtype box = new Boxtype(); Circletype circle1 = new Circletype(); Arctype arc = new Arctype(); TEXTtype text = new TEXTtype(); CCfgtype cfg = new CCfgtype(); // Cfgtype cfg1; double last_x1; double last_y1; double last_x2; double last_y2; BinaryReader fhandle; //int fhandle; double LWidthDbl = 0; //'/l->line double BWidthDbl; //'/b->box double AWidthDbl; //'/ a->text double CWidthDbl; //'/c->circle //double RotAngle = 0; IHdPolyline3D pLine; //DrgReturn Retval; //int i = 0; CCfgtype tempcfg = new CCfgtype(); // CWaitCursor wait; long NumPts = 0; //if (!bEngFunc) //{ // CDocument* pDocument = theApp.m_pDocTemplate->CreateNewDocument(); // BOOL bAutoDelete = pDocument->m_bAutoDelete; // pDocument->m_bAutoDelete = FALSE; // don't destroy if something goes wrong // CFrameWnd* pFrame = theApp.m_pDocTemplate->CreateNewFrame(pDocument, NULL); // pDocument->m_bAutoDelete = bAutoDelete; // pDocument->SetPathName(szFileName); // theApp.m_pDocTemplate->InitialUpdateFrame(pFrame, pDocument, TRUE); //} fhandle = new BinaryReader(new FileStream(szFileName, FileMode.Open), Encoding.Default); pLine = null; cfg = app.ActiveDocument.ConfigParam; while (fhandle.BaseStream.Position < fhandle.BaseStream.Length) { eld.Code = 0; eld.Code = fhandle.ReadInt16(); if (eld.Code == 99) { if (sType == "PVR" && (!bEngFunc)) { cfg = CCfgtype.FromStream(fhandle); app.ActiveDocument.ConfigParam = cfg; } else { tempcfg = CCfgtype.FromStream(fhandle); } //RotAngle = 0; NumPts = 0; } else if (eld.Code == 1) { line = Linetype.FromStream(fhandle); XlateNmat(ref line.x1, ref line.y1, cfg.XMetric, cfg.YMetric); XlateNmat(ref line.x2, ref line.y2, cfg.XMetric, cfg.YMetric); LWidthDbl = (double)(line.width); //Convert result into double NumPts = NumPts + 1; if (line.scatt == 1) { line.style = (short)(line.style - 1); // to check this d deb 30/aug/01 if (pLine == null) { List <CPoint3D> listpt = new List <CPoint3D>(); listpt.Add(new CPoint3D(line.x1, line.y1, line.z1)); listpt.Add(new CPoint3D(line.x2, line.y2, line.z2)); pLine = app.ActiveDocument.DrawPolyline3D(listpt); DrawingUtil.SetLayerToEntity(bEngFunc, pLine, app.ActiveDocument, line.layer); pLine.Label = sType; } else { pLine.AppendVertex(new CPoint3D(line.x2, line.y2, line.z2)); } } last_x1 = line.x1; last_y1 = line.y1; last_x2 = line.x2; last_y2 = line.y2; } else if (eld.Code == 2) { box = Boxtype.FromStream(fhandle); box.style = (short)(box.style - 1); XlateNmat(ref box.x1, ref box.y1, cfg.XMetric, cfg.YMetric); XlateNmat(ref box.x2, ref box.y2, cfg.XMetric, cfg.YMetric); BWidthDbl = (double)(box.Width); if (box.scatt == 1) { IHdPolyline3D polyRect = DrawingUtil.DrawRect(app.ActiveDocument , new CPoint3D(box.x1, box.y1, 0) , new CPoint3D(box.x2, box.y2, 0)); DrawingUtil.SetLayerToEntity(bEngFunc, polyRect, app.ActiveDocument, box.Layer); polyRect.Label = sType; } } else if (eld.Code == 3) { circle1 = Circletype.FromStream(fhandle); circle1.style = (short)(circle1.style - 1); XlateNmat(ref circle1.xc, ref circle1.yc, cfg.XMetric, cfg.YMetric); CWidthDbl = (double)(circle1.Width); if (circle1.scatt == 1) { IHdEllipse hdellipse = app.ActiveDocument.DrawEllipse(new CPoint3D(circle1.xc, circle1.yc, 0), circle1.Radius); DrawingUtil.SetLayerToEntity(bEngFunc, hdellipse, app.ActiveDocument, circle1.Layer); circle1.Label = sType; } } else if (eld.Code == 4) { arc = Arctype.FromStream(fhandle); arc.style = (short)(arc.style - 1); XlateNmat(ref arc.xc, ref arc.yc, cfg.XMetric, cfg.YMetric); XlateNmat(ref arc.xs, ref arc.ys, cfg.XMetric, cfg.YMetric); XlateNmat(ref arc.xe, ref arc.ye, cfg.XMetric, cfg.YMetric); AWidthDbl = (double)(arc.Width); if (arc.scatt != 0) { IHdArc hdarc = DrawingUtil.DrawArc(app.ActiveDocument, arc.xs, arc.ys, arc.xe, arc.ye, arc.xc, arc.yc, arc.Radius); DrawingUtil.SetLayerToEntity(bEngFunc, hdarc, app.ActiveDocument, arc.Layer); hdarc.Label = sType; } } else if (eld.Code == 9) { text = TEXTtype.FromStream(fhandle); text.style = (short)(text.style - 1); XlateNmat(ref text.x1, ref text.y1, cfg.XMetric, cfg.YMetric); if (text.scatt != 0) { IHdText hdtext = app.ActiveDocument.DrawText(new CPoint3D(text.x1, text.y1, 0), text.text, text.Size); DrawingUtil.SetLayerToEntity(bEngFunc, hdtext, app.ActiveDocument, text.Layer); hdtext.Rotate(new CPoint3D(text.x1, text.y1, 0), text.rotn); hdtext.Label = sType; } } } fhandle.Close(); }
public static void DrawChainage(IHeadsApplication app, string szFileName, string sType, bool bEngFunc) { // 11/09/01 Eldtype eld = new Eldtype(); Linetype line = new Linetype(); Boxtype box = new Boxtype(); Circletype circle1 = new Circletype(); Arctype arc = new Arctype(); TEXTtype text = new TEXTtype(); CCfgtype cfg = new CCfgtype(); BinaryReader fhandle; //int fhandle; double LWidthDbl = 0; //'/l->line double BWidthDbl; //'/b->box double AWidthDbl; //'/ a->text double CWidthDbl; //'/c->circle //double RotAngle = 0; //IHdPolyline3D pLine; // no plines req d deb //CvdSelection MySelSet; // renentry d deb 11/09/01 //CVdView *drawing = NULL; //frmDrawing drawing; //DrgReturn Retval; //int i = 0; CCfgtype tempcfg = new CCfgtype(); long NumPts = 0; //if(!bEngFunc) //{ // CDocument* pDocument = theApp.m_pDocTemplate->CreateNewDocument(); // BOOL bAutoDelete = pDocument->m_bAutoDelete; // pDocument->m_bAutoDelete = FALSE; // don't destroy if something goes wrong // CFrameWnd* pFrame = theApp.m_pDocTemplate->CreateNewFrame(pDocument, NULL); // pDocument->m_bAutoDelete = bAutoDelete; // pDocument->SetPathName(szFileName); // theApp.m_pDocTemplate->InitialUpdateFrame(pFrame, pDocument, TRUE); //} //drawing = (CVdView*)GetCurrentView(); if (File.Exists(szFileName) == false) { return; } fhandle = new BinaryReader(new FileStream(szFileName, FileMode.Open), Encoding.Default); // if(bEngFunc) cfg = app.ActiveDocument.ConfigParam; while (fhandle.BaseStream.Position < fhandle.BaseStream.Length) { eld.Code = fhandle.ReadInt16(); if (eld.Code == 99) { if (sType == "PVR" && (!bEngFunc)) { cfg = CCfgtype.FromStream(fhandle); app.ActiveDocument.ConfigParam = cfg; } else { tempcfg = CCfgtype.FromStream(fhandle); } //RotAngle = 0; NumPts = 0; } else if (eld.Code == 1) // line { line = Linetype.FromStream(fhandle); XlateNmat(ref line.x1, ref line.y1, cfg.XMetric, cfg.YMetric); XlateNmat(ref line.x2, ref line.y2, cfg.XMetric, cfg.YMetric); LWidthDbl = (double)(line.width); //Convert to double NumPts = NumPts + 1; if (line.scatt == 1) { IHdLine Entity = app.ActiveDocument.DrawLine(new CPoint3D(line.x1, line.y1, line.z1), new CPoint3D(line.x2, line.y2, line.z2)); if (Entity != null) { if (!bEngFunc) { string layerName = line.layer; DrawingUtil.SetLayerToEntity(bEngFunc, Entity, app.ActiveDocument, layerName); //Entity.SetPenStyle(line.style); //Entity.SetPenWidth(LWidthDbl); } } Entity.Label = sType; } } else if (eld.Code == 2) { box = Boxtype.FromStream(fhandle); box.style = (short)(box.style - 1); XlateNmat(ref box.x1, ref box.y1, cfg.XMetric, cfg.YMetric); XlateNmat(ref box.x2, ref box.y2, cfg.XMetric, cfg.YMetric); BWidthDbl = (double)(box.Width); if (box.scatt == 1) { IHdPolyline3D polyRect = DrawingUtil.DrawRect(app.ActiveDocument , new CPoint3D(box.x1, box.y1, 0) , new CPoint3D(box.x2, box.y2, 0)); DrawingUtil.SetLayerToEntity(bEngFunc, polyRect, app.ActiveDocument, box.Layer); polyRect.Label = sType; } } else if (eld.Code == 3) { circle1 = Circletype.FromStream(fhandle); circle1.style = (short)(circle1.style - 1); XlateNmat(ref circle1.xc, ref circle1.yc, cfg.XMetric, cfg.YMetric); CWidthDbl = (double)(circle1.Width); if (circle1.scatt == 1) { IHdEllipse hdellipse = app.ActiveDocument.DrawEllipse(new CPoint3D(circle1.xc, circle1.yc, 0), circle1.Radius); DrawingUtil.SetLayerToEntity(bEngFunc, hdellipse, app.ActiveDocument, circle1.Layer); hdellipse.Label = sType; } } else if (eld.Code == 4) { arc = Arctype.FromStream(fhandle); arc.style = (short)(arc.style - 1); XlateNmat(ref arc.xc, ref arc.yc, cfg.XMetric, cfg.YMetric); XlateNmat(ref arc.xs, ref arc.ys, cfg.XMetric, cfg.YMetric); XlateNmat(ref arc.xe, ref arc.ye, cfg.XMetric, cfg.YMetric); AWidthDbl = (double)(arc.Width); if (arc.scatt != 0) { IHdArc hdarc = DrawingUtil.DrawArc(app.ActiveDocument, arc.xs, arc.ys, arc.xe, arc.ye, arc.xc, arc.yc, arc.Radius); DrawingUtil.SetLayerToEntity(bEngFunc, hdarc, app.ActiveDocument, arc.Layer); hdarc.Label = sType; } } else if (eld.Code == 9) { text = TEXTtype.FromStream(fhandle); text.style = (short)(text.style - 1); XlateNmat(ref text.x1, ref text.y1, cfg.XMetric, cfg.YMetric); if (text.scatt != 0) { IHdText hdtext = app.ActiveDocument.DrawText(new CPoint3D(text.x1, text.y1, 0), text.text, text.Size); DrawingUtil.SetLayerToEntity(bEngFunc, hdtext, app.ActiveDocument, text.Layer); hdtext.Rotate(new CPoint3D(text.x1, text.y1, 0), ViewerUtils.DegreeToRadian(text.rotn)); hdtext.Label = sType; //DrawText(bEngFunc, text.text, text.x1, text.y1, text.Size, text.Color, text.style, text.Label, text.Layer, text.rotn, sType); } } } fhandle.Close(); }
public static void ImportFromDRG(IHeadsApplication app, string strPath, string sType, bool bEngFunc) { app.ActiveDocument.DisableUndoRecording(true); CCfgtype cfg = app.ActiveDocument.ConfigParam; Linetype line = null; Circletype circle1 = null; TEXTtype text = null; Arctype arc = null; BinaryReader br = new BinaryReader(new FileStream(strPath, FileMode.Open, FileAccess.Read), Encoding.Default); Eldtype eld = new Eldtype(); while (br.BaseStream.Position < br.BaseStream.Length) { eld.Code = br.ReadInt16(); if (GetDrgEleType(eld.Code) == DrgEleType.CONFIG) { if (sType == "PVR" && (!bEngFunc)) { cfg = CCfgtype.FromStream(br); app.ActiveDocument.ConfigParam = cfg; } else { CCfgtype tempcfg = CCfgtype.FromStream(br); } } else if (GetDrgEleType(eld.Code) == DrgEleType.LINE) { line = Linetype.FromStream(br); XlateNmat(ref line.x1, ref line.y1, cfg.XMetric, cfg.YMetric); XlateNmat(ref line.x2, ref line.y2, cfg.XMetric, cfg.YMetric); //LWidthDbl = (double)(line.Width); //Convert result into double :::why? //NumPts = NumPts + 1; if (line.scatt == 1) { line.style = (short)(line.style - 1); IHdLine aLine = app.ActiveDocument.DrawLine(line.StartPoint, line.EndPoint); aLine.ColorIndex = line.color; SetLayerToEntity(bEngFunc, aLine, app.ActiveDocument, line.layer); }//end if(line.scatt == 1) } else if (GetDrgEleType(eld.Code) == DrgEleType.ELLIPSE) { circle1 = Circletype.FromStream(br); circle1.style = (short)(circle1.style - 1); // circle1.Color = HeadsToVDraw(circle1.Color); XlateNmat(ref circle1.xc, ref circle1.yc, cfg.XMetric, cfg.YMetric); //CWidthDbl = (double)(circle1.Width); if (circle1.scatt == 1) { IHdEllipse ellipse = app.ActiveDocument.DrawEllipse(new CPoint3D(circle1.xc, circle1.yc, 0), circle1.Radius); //DrawCircle(bEngFunc, circle1.xc, circle1.yc, circle1.Radius, circle1.Color, circle1.style, CWidthDbl, circle1.Label, circle1.Layer, RotAngle, sType); SetLayerToEntity(bEngFunc, ellipse, app.ActiveDocument, circle1.Layer); ellipse.Label = circle1.Label; ellipse.ColorIndex = circle1.color; } } else if (GetDrgEleType(eld.Code) == DrgEleType.ARC) { arc = Arctype.FromStream(br); arc.style = (short)(arc.style - 1); // arc.Color = HeadsToVDraw(arc.Color); XlateNmat(ref arc.xc, ref arc.yc, cfg.XMetric, cfg.YMetric); XlateNmat(ref arc.xs, ref arc.ys, cfg.XMetric, cfg.YMetric); XlateNmat(ref arc.xe, ref arc.ye, cfg.XMetric, cfg.YMetric); //AWidthDbl = (double)(arc.Width); if (arc.scatt == 1) { IHdArc hdarc = DrawArc(app.ActiveDocument, arc.xs, arc.ys, arc.xe, arc.ye, arc.xc, arc.yc, arc.Radius); SetLayerToEntity(bEngFunc, hdarc, app.ActiveDocument, arc.Layer); hdarc.Label = arc.Label; hdarc.ColorIndex = arc.Color; } } else if (GetDrgEleType(eld.Code) == DrgEleType.TEXT) { text = TEXTtype.FromStream(br); text.style = (short)(text.style - 1); XlateNmat(ref text.x1, ref text.y1, cfg.XMetric, cfg.YMetric); if (text.scatt != 0) { IHdText hdtext = app.ActiveDocument.DrawText(new CPoint3D(text.x1, text.y1, 0), text.text, text.Size); DrawingUtil.SetLayerToEntity(bEngFunc, hdtext, app.ActiveDocument, text.Layer); hdtext.Label = text.Label; hdtext.Rotate(new CPoint3D(text.x1, text.y1, 0), ViewerUtils.DegreeToRadian(text.rotn)); hdtext.ColorIndex = text.Color; } } } br.Close(); app.ActiveDocument.DisableUndoRecording(false); app.ZoomExtents(); }
public void ApplyLayout(IHeadsApplication app) { if (this.LastAppliedLayoutID != 0) { if (MessageBox.Show("Last applied layout not accepted.\nDo you want to cancel the last applied layout?" , "Layout", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } //this.LastAppliedLayout = null; if (this.LastAppliedLayoutID != 0) { IHdEntity entity = app.ActiveDocument.GetObjectById(this.LastAppliedLayoutID); if (entity != null) { entity.Erase(); app.ActiveDocument.RefreshDocument(); } this.LastAppliedLayoutID = 0; } Layout.FormLayout formlayout = new Layout.FormLayout(); if (this.LastAppliedLayout != null) { formlayout.SelectedLayout = this.LastAppliedLayout; } if (formlayout.ShowDialog() == DialogResult.OK) { CPoint3D ptBottomLeft = app.ActiveDocument.GetUserPoint("Select the bottom-left edge to place the sheet"); if (ptBottomLeft != null) { this.LastAppliedLayout = formlayout.SelectedLayout; CCfgtype cfg = app.ActiveDocument.ConfigParam; double ActualHeight; double ActualWidth; double x2, y2, x11, y11, x22, y22; double x = ptBottomLeft.X; double y = ptBottomLeft.Y; double Xpos = x * cfg.XMetric; double Ypos = y * cfg.YMetric; ActualHeight = this.LastAppliedLayout.sheetLength * (this.LastAppliedLayout.layOutScale / 1000.00); ActualWidth = this.LastAppliedLayout.sheetWidth * (this.LastAppliedLayout.layOutScale / 1000.00); x2 = Xpos + ActualWidth; y2 = Ypos + ActualHeight; x11 = Xpos + this.LastAppliedLayout.leftM * (this.LastAppliedLayout.layOutScale / 1000.00); y11 = Ypos + this.LastAppliedLayout.bottomM * (this.LastAppliedLayout.layOutScale / 1000.00); x22 = x2 - this.LastAppliedLayout.rightM * (this.LastAppliedLayout.layOutScale / 1000.00); y22 = y2 - this.LastAppliedLayout.topM * (this.LastAppliedLayout.layOutScale / 1000.00); this.LastAppliedLayoutID = AddPolyLineLayout(app, Xpos, Ypos, x2, y2, x11, y11, x22, y22); app.ActiveDocument.RefreshDocument(); } } }
private void ExecDrawString(BinaryReader br) { bool bIsModel = false; bool bIsLabel = false; CPoint3D ptStart = new CPoint3D(); CPoint3D ptEnd = new CPoint3D(); CPoint3D ptLast = new CPoint3D(); CPoint3D ptFirst3dFac = new CPoint3D(); string strSeleModel = GetSelectedModelName(); CTXTtype txt = new CTXTtype(); CLinetype uline = new CLinetype(); string strModelName = ""; int NumPts = 0; string str1 = ""; string stgLabel = ""; IHdPoint aPoint = null; IHdPolyline3D polyline = null; CPTStype pts = new CPTStype(); List <CPoint3D> pFArray = new List <CPoint3D>(); this.m_app.ActiveDocument.ConfigParam.XMetric = 1.0; this.m_app.ActiveDocument.ConfigParam.YMetric = 1.0; CCfgtype cfg = this.m_app.ActiveDocument.ConfigParam; int iSelectedLineType = this.GetSelectedLineType(); double dTextHeight = (this.m_app.ActiveDocument.ActiveTextHeight > 0) ? this.m_app.ActiveDocument.ActiveTextHeight : 1.0; string strFilePath = m_strpathfilfile; //if (File.Exists(strFilePath)) { //BinaryReader br = new BinaryReader(new FileStream(strFilePath, FileMode.Open, FileAccess.Read), Encoding.Default); //set the progress bar max value SetProgressBarMaxValue(100); while (br.BaseStream.Position < br.BaseStream.Length) { CLabtype labtype = CLabtype.FromStream(br); if (labtype.attr == CLabtype.Type.Model) // Model Name { NumPts = 0; strModelName = ((CModType)labtype.Tag).Name; bIsModel = (strModelName == strSeleModel) ? true : false; } else if (labtype.attr == CLabtype.Type.String)// String Label { stgLabel = ((CStgType)labtype.Tag).label; if (bIsModel) { bIsLabel = this.lbStringLebels_.CheckedItems.Contains(stgLabel); } } else if (labtype.attr == CLabtype.Type.Point) { pts = (CPTStype)labtype.Tag; ptEnd = new CPoint3D(pts.mx * cfg.XMetric, pts.my * cfg.YMetric, pts.mz); NumPts++; ptStart = ptLast; ptLast = ptEnd; if (bIsModel && bIsLabel) { uline.StartPoint = new CPoint3D(ptStart); uline.EndPoint = new CPoint3D(ptEnd); str1 = stgLabel; if (str1.ToUpper().StartsWith("P") == true) { if (str1.ToUpper().StartsWith("P0") == true) { txt.Point = ptEnd; //double[] res = ptEnd.GetCordArr(); txt.tr = 0.0; str1 = ptEnd.Z.ToString("0.000"); this.m_app.ActiveDocument.DrawText(new CPoint3D(ptEnd.X, ptEnd.Y, dTextHeight), str1, dTextHeight); this.m_app.ActiveDocument.DrawLine(new CPoint3D(ptEnd.X - 0.5, ptEnd.Y, ptEnd.Z), new CPoint3D(ptEnd.X + 0.5, ptEnd.Y, ptEnd.Z)); this.m_app.ActiveDocument.DrawLine(new CPoint3D(ptEnd.X, ptEnd.Y - 0.5, ptEnd.Z), new CPoint3D(ptEnd.X, ptEnd.Y + 0.5, ptEnd.Z)); } else { txt.Point = ptEnd; txt.tr = 0.0; double[] res = ptEnd.GetCordArr(); this.m_app.ActiveDocument.DrawText(new CPoint3D(ptEnd.X, ptEnd.Y, dTextHeight), str1, dTextHeight); this.m_app.ActiveDocument.DrawLine(new CPoint3D(ptEnd.X - 0.5, ptEnd.Y, ptEnd.Z), new CPoint3D(ptEnd.X + 0.5, ptEnd.Y, ptEnd.Z)); this.m_app.ActiveDocument.DrawLine(new CPoint3D(ptEnd.X, ptEnd.Y - 0.5, ptEnd.Z), new CPoint3D(ptEnd.X, ptEnd.Y + 0.5, ptEnd.Z)); } } else { if (NumPts == 1) { aPoint = this.m_app.ActiveDocument.DrawPoint(ptEnd); if (iSelectedLineType == 4) { aPoint.Erase(); ptFirst3dFac = new CPoint3D(ptEnd); pFArray.Add(ptEnd); } } else if (NumPts == 2) { uline.Layer = this.m_app.ActiveDocument.GetActiveLayer().Name; uline.elatt = 1; uline.laatt = 1; uline.Label = strModelName; uline.Label += ":"; uline.Label += stgLabel; uline.scatt = 1; if (iSelectedLineType == 1) { polyline = DrawingUtil.DrawPolyline3DDx(this.m_app.ActiveDocument, true, uline); } else if (iSelectedLineType == 2) { polyline = DrawingUtil.DrawPolyline3DDx(this.m_app.ActiveDocument, true, uline); } else if (iSelectedLineType == 3) { aPoint = this.m_app.ActiveDocument.DrawPoint(ptEnd); } else if (iSelectedLineType == 4) { pFArray.Add(ptEnd); } aPoint.Erase(); } else if (NumPts > 2) { if (iSelectedLineType == 1) { polyline.AppendVertex(ptEnd); } else if (iSelectedLineType == 2) { polyline = DrawingUtil.DrawPolyline3DDx(this.m_app.ActiveDocument, true, uline); } else if (iSelectedLineType == 3) { aPoint = this.m_app.ActiveDocument.DrawPoint(ptEnd); } else if (iSelectedLineType == 4) { pFArray.Add(ptEnd); } } } } } else if (labtype.attr == CLabtype.Type.Text) { txt = (CTXTtype)labtype.Tag; ptEnd = new CPoint3D(txt.tx * cfg.XMetric, txt.ty * cfg.YMetric, txt.tz); if (bIsLabel && bIsModel) { str1 = txt.tg; //Display an Elevation //TO DO: this.m_app.ActiveDocument.DrawText(ptEnd, str1, dTextHeight); aPoint = this.m_app.ActiveDocument.DrawPoint(ptEnd); } } else if (labtype.attr == CLabtype.Type.EndCode) { if ((iSelectedLineType == 4) && (bIsLabel && bIsModel)) { if ((System.Math.Abs(ptEnd.X - ptFirst3dFac.X) > 0.00001) || (System.Math.Abs(ptEnd.Y - ptFirst3dFac.Y) > 0.00001)) { if (NumPts < 4) { pFArray.Add(ptFirst3dFac); //close the face } } if (pFArray.Count > 3) { IHd3DFace face3d = this.m_app.ActiveDocument.Draw3DFace(pFArray[0], pFArray[1], pFArray[2], pFArray[3]); face3d.Update(); } pFArray.Clear(); } NumPts = 0; } int iCurProgressInPercent = (int)(((double)br.BaseStream.Position / (double)br.BaseStream.Length) * 100.00); SetProgressBarValue(iCurProgressInPercent); Thread.Sleep(0); } //br.Close(); } }