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 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 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(); }