public static void ModifyingXData() { Line line = new Line(Vector2.Zero, Vector2.UnitX); ApplicationRegistry appReg = new ApplicationRegistry("netDxf"); XData xdata = new XData(appReg); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "Length")); line.XData.Add(xdata); DxfDocument doc = new DxfDocument(); doc.AddEntity(line); // modifying existing extended data line.XData[appReg.Name].XDataRecord.Add(new XDataRecord(XDataCode.Real, Vector3.Distance(line.StartPoint, line.EndPoint))); // adding new extended data entry to an existing entity ApplicationRegistry appReg2 = new ApplicationRegistry("newXData"); XData xdata2 = new XData(appReg2); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "XData entries")); line.XData.Add(xdata2); Debug.Assert(ReferenceEquals(line.XData[appReg2.Name].ApplicationRegistry, doc.ApplicationRegistries[appReg2.Name])); // deleting existing extended data line.XData.Remove(appReg.Name); // we can also change the name of the application registry name doc.ApplicationRegistries["newXData"].Name = "netDxfRenamed"; doc.Save("xData.dxf"); doc = DxfDocument.Load("xData.dxf"); }
private void DrawGridInternal(DxfDocument doc, Layer layer, Core2D.ShapeStyle style, double offsetX, double offsetY, double cellWidth, double cellHeight, ref Core2D.Rect2 rect) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); double ox = rect.X; double oy = rect.Y; double sx = ox + offsetX; double sy = oy + offsetY; double ex = ox + rect.Width; double ey = oy + rect.Height; for (double gx = sx; gx < ex; gx += cellWidth) { var dxfLine = CreateLine(gx, oy, gx, ey); dxfLine.Layer = layer; dxfLine.Color = stroke; dxfLine.Transparency.Value = strokeTansparency; dxfLine.Lineweight.Value = lineweight; doc.AddEntity(dxfLine); } for (double gy = sy; gy < ey; gy += cellHeight) { var dxfLine = CreateLine(ox, gy, ex, gy); dxfLine.Layer = layer; dxfLine.Color = stroke; dxfLine.Transparency.Value = strokeTansparency; dxfLine.Lineweight.Value = lineweight; doc.AddEntity(dxfLine); } }
public static DxfDocument generateDXF(StructuralModel structure) { var dxf = new netDxf.DxfDocument(); var ColumnLayer = new netDxf.Tables.Layer("Column") { Color = netDxf.AciColor.Red, Lineweight = netDxf.Lineweight.W50 }; var SlabLayer = new netDxf.Tables.Layer("Slab") { Color = netDxf.AciColor.Yellow, Lineweight = netDxf.Lineweight.W50 }; var OpeningLayer = new netDxf.Tables.Layer("Opening") { Color = netDxf.AciColor.Blue, Lineweight = netDxf.Lineweight.W50 }; var WallLayer = new netDxf.Tables.Layer("Wall") { Color = netDxf.AciColor.Green, Lineweight = netDxf.Lineweight.W50 }; dxf.Layers.Add(ColumnLayer); dxf.Layers.Add(SlabLayer); dxf.Layers.Add(OpeningLayer); dxf.Layers.Add(WallLayer); foreach (var item in structure.Columns) { dxf.AddEntity(getPolylineFromPoints(item.Points, ColumnLayer)); } foreach (var item in structure.Slabs) { dxf.AddEntity(getPolylineFromPoints(item.Points, SlabLayer)); } foreach (var item in structure.Walls) { dxf.AddEntity(getPolylineFromPoints(item.Points, WallLayer, false)); } foreach (var item in structure.Openings) { dxf.AddEntity(getPolylineFromPoints(item.Points, OpeningLayer)); } return(dxf); }
public static void Draw(DxfDocument dxf, Location location) { Vector3f v1 = new Vector3f(location.X - 2.0f, location.Y + 4.0f, location.Z); Vector3f v2 = new Vector3f(location.X + 2.0f, location.Y + 4.0f, location.Z); Vector3f v0=new Vector3f(location.X,location.Y,location.Z); Layer layer = new Layer("line"); Line line10 = new Line(v0, v1); line10.Layer = layer; dxf.AddEntity(line10); Line line20 = new Line(v0, v2); line20.Layer = layer; dxf.AddEntity(line20); }
/// <summary> /// 绘制风扇 /// </summary> /// <param name="dxf"></param> /// <param name="startPoint">风扇起点,如果为横置,由左向右;如果为竖置,由下到上</param> /// <param name="endPoint">风扇终点,如果为横置,由左向右;如果为竖置,由下到上</param> /// <param name="pointerLocation">箭头位置,默认=0为无,=1代表箭头在中间,=2代表箭头在底部</param> public static void Draw(DxfDocument dxf, Vector3f startPoint, Vector3f endPoint,int pointerLocation=0) { Layer layer = new Layer("line"); Line line = new Line(startPoint, endPoint); line.Layer = layer; dxf.AddEntity(line); //如果为横置 if (startPoint.Y == endPoint.Y) { float segment = (endPoint.X - startPoint.X) / 4; Slash.Draw(dxf, new Location(startPoint.X + segment, startPoint.Y, startPoint.Z)); Slash.Draw(dxf, new Location(startPoint.X + 2 * segment, startPoint.Y, startPoint.Z)); Slash.Draw(dxf, new Location(startPoint.X + 3 * segment, startPoint.Y, startPoint.Z)); } //如果为竖置 else if (startPoint.X == endPoint.X) { float segment = (endPoint.Y - startPoint.Y) / 5; Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + segment, startPoint.Z)); Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + 2 * segment, startPoint.Z)); Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + 3 * segment, startPoint.Z)); Slash.Draw(dxf, new Location(startPoint.X, startPoint.Y + 4 * segment, startPoint.Z)); if (pointerLocation == 1) { LinePointer.Draw(dxf,new Location(startPoint.X,(startPoint.Y+endPoint.Y)/2,startPoint.Z)); } else if(pointerLocation==2) { LinePointer.Draw(dxf, new Location(startPoint.X, startPoint.Y, startPoint.Z)); } } }
protected override Task _save() { RecordSet layer = _layer as RecordSet; layer.Position = transform.position.ToPoint(); layer.Transform.Position = Vector3.zero; layer.Transform.Rotate = transform.rotation; layer.Transform.Scale = transform.localScale; EditableMesh[] meshes = GetComponentsInChildren <EditableMesh>(); string ex = Path.GetExtension(layer.Source).ToLower(); features = new List <DMesh3>(); foreach (EditableMesh mesh in meshes) { features.Add(mesh.GetMesh()); } if (ex == ".obj") { List <WriteMesh> wmeshes = new List <WriteMesh>(); foreach (DMesh3 dmesh in features) { DMesh3 mesh = new DMesh3(dmesh); foreach (int idx in mesh.VertexIndices()) { Vector3d vtx = mesh.GetVertex(idx); mesh.SetVertex(idx, new Vector3d(vtx.x, vtx.z, vtx.y)); } wmeshes.Add(new WriteMesh(mesh, "")); } saveObj(layer.Source, wmeshes); } if (ex == ".dxf") { DXF.DxfDocument doc = new DXF.DxfDocument(); CoordinateTransformation transform = null; if (GetCrs() != null) { transform = new CoordinateTransformation(AppState.instance.mapProj, GetCrs()); } foreach (DMesh3 dmesh in features) { foreach (Index3i tri in dmesh.Triangles()) { DXF.Vector3 v1 = dmesh.GetVertex(tri.a).ToDxfVector3(transform); DXF.Vector3 v2 = dmesh.GetVertex(tri.b).ToDxfVector3(transform); DXF.Vector3 v3 = dmesh.GetVertex(tri.c).ToDxfVector3(transform); doc.AddEntity(new Face3d(v1, v2, v3)); } } using (Stream stream = File.Open(layer.Source, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) { doc.Save(stream); stream.Close(); } } return(Task.CompletedTask); }
private void DrawEllipseInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Core2D.BaseStyle style, ref Core2D.Rect2 rect) { var dxfEllipse = CreateEllipse(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); // TODO: The netDxf does not create hatch for Ellipse with end angle equal to 360. var bounds = new List <HatchBoundaryPath> { new HatchBoundaryPath( new List <EntityObject> { (Ellipse)dxfEllipse.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; doc.AddEntity(hatch); } if (isStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfEllipse.Layer = layer; dxfEllipse.Color = stroke; dxfEllipse.Transparency.Value = strokeTansparency; dxfEllipse.Lineweight.Value = lineweight; doc.AddEntity(dxfEllipse); } }
public static void Draw(DxfDocument dxf, Location location,List<string> configurations) { Vector3f confStrVector3f = new Vector3f(location.X + 5.0f, location.Y - 5.0f, location.Z); TextStyle style = new TextStyle("True type font", "Arial.ttf"); Text text1 = new Text("CONFIGURATION: NOTE: Assembly drawing for overall dimesions, actual door size and handle position may vary", confStrVector3f, 2.0f, style); Layer layer = new Layer("text"); text1.Layer = layer; //text1.Layer.Color.Index = 8; text1.Alignment = TextAlignment.TopLeft; dxf.AddEntity(text1); for (int i = 0; i < configurations.Count(); i++) { Vector3f confVector3f = new Vector3f(location.X+10.0f, location.Y - 5.0f * (i + 2), location.Z); Text text = new Text(configurations[i], confVector3f, 2.0f, style); text.Layer = layer; //text.Layer.Color.Index = 8; text.Alignment = TextAlignment.TopLeft; dxf.AddEntity(text); } }
/// <summary> /// 风向绘制 /// </summary> /// <param name="dxf"></param> /// <param name="location"></param> /// <param name="isRight"></param> public static void Draw(DxfDocument dxf, Location location, bool isRight) { float factor = 0.5f; Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); Vector3f v3 = new Vector3f(); Vector3f v4 = new Vector3f(); Vector3f v5 = new Vector3f(); Vector3f v6 = new Vector3f(); Vector3f v7 = new Vector3f(); if (isRight) { v1 = new Vector3f(10*factor + location.X, location.Y, location.Z); v2 = new Vector3f(location.X, location.Y + 10 * factor, location.Z); v3 = new Vector3f(location.X + 10 * factor, location.Y + 10 * factor, location.Z); v4 = new Vector3f(location.X + 20 * factor, location.Y + 15 * factor, location.Z); v5 = new Vector3f(location.X, location.Y + 20 * factor, location.Z); v6 = new Vector3f(location.X + 10 * factor, location.Y + 20 * factor, location.Z); v7 = new Vector3f(location.X + 10 * factor, location.Y + 30 * factor, location.Z); } else { v1 = new Vector3f(10 * factor + location.X, location.Y, location.Z); v2 = new Vector3f(location.X + 20 * factor, location.Y + 10 * factor, location.Z); v3 = new Vector3f(location.X + 10 * factor, location.Y + 10 * factor, location.Z); v4 = new Vector3f(location.X, location.Y + 15 * factor, location.Z); v5 = new Vector3f(location.X + 20 * factor, location.Y + 20 * factor, location.Z); v6 = new Vector3f(location.X + 10 * factor, location.Y + 20 * factor, location.Z); v7 = new Vector3f(location.X + 10 * factor, location.Y + 30 * factor, location.Z); } Layer layer = new Layer("line"); Line line23 = new Line(v2, v3); line23.Layer = layer; dxf.AddEntity(line23); Line line56 = new Line(v5, v6); line56.Layer = layer; dxf.AddEntity(line56); Line line14 = new Line(v1, v4); line14.Layer = layer; dxf.AddEntity(line14); Line line74 = new Line(v7, v4); line74.Layer = layer; dxf.AddEntity(line74); Line line25 = new Line(v2, v5); line25.Layer = layer; dxf.AddEntity(line25); Line line71 = new Line(v7, v1); line71.Layer = layer; dxf.AddEntity(line71); }
static void Main(string[] args) { var dxf = new netDxf.DxfDocument(); var rValues1 = new List <double>() { 1, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82, 100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680, 820, 1e3, 1.2e3, 1.5e3, 1.8e3, 2.2e3, 2.7e3, 3.3e3, 3.9e3, 4.7e3, 5.5e3, 6.8e3, 7.2e3, 8.2e3, 10e3, 12e3, 15e3, 18e3, 22e3, 27e3, 33e3, 39e3, 47e3, 56e3, 82e3, 100e3, 120e3, 150e3, 180e3, 220e3, 270e3, 330e3, 380e3, 470e3, 560e3, 680e3, 820e3, 1e6, 1.2e6, 1.5e6, 1.8e6, 2.2e6, 2.7e6, 3.3e6, 3.9e6, 4.7e6, 5.6e6, 6.8e6, 8.2e6, 10e6 }; var rValues2 = new List <double>() { 7.5, 75, 200, 510, 2e3, 3e3, 5.1e3, 7.5e3, 20e3, 51e3, 68e3, 75e3, 200e3, 510e3, 750e3, 2e6 }; var rValues3 = new List <double>() { 1.2, 1.5, 1.8, 2.7, 3.3, 3.9, 6.8, 12, 18, 560, 820, 1.2e3, 1.8e3, 2.7e3, 12e3, 18e3, 27e3, 270e3, 380e3, 5.6e3, 300e3, 1.2e6, 1.8e6, 2.2e6, 2.7e6, 3.9e6, 6.8e6, 8.2e6 }; var DATA = rValues1.Union(rValues2).Union(rValues3).OrderBy(w => w).ToList(); var PAGE_W = 210d; var PAGE_H = 297d; var LABEL_W = 25d; var LABEL_H = 20d; var MARGINS_LTRB = new[] { 10d, 10d, 10d, 10d }; var COLS = Math.Truncate((PAGE_W - MARGINS_LTRB[0] - MARGINS_LTRB[2]) / LABEL_W); var ROWS = Math.Truncate((PAGE_H - MARGINS_LTRB[1] - MARGINS_LTRB[3]) / LABEL_H); var XORIGIN = 0d; var YORIGIN = 0d; var TXT_HEIGHT = 5d; var OHM_HEIGHT = 3d; var TXT_FONT = new netDxf.Tables.TextStyle("Ubuntu Condensed", netDxf.Tables.FontStyle.Regular); var x = XORIGIN; var y = YORIGIN; int page = 0; for (int i = 0; i < DATA.Count; ++i) { var r = DATA[i]; var prefix = ""; if (r >= 1e6) { prefix = " M"; r /= 1e6; } else if (r >= 1e3) { prefix = " k"; r /= 1e3; } var txt = Invariant($"\\H{TXT_HEIGHT};{r}{prefix} \\H{OHM_HEIGHT};Ω"); { var ent = new LwPolyline(new[] { new Vector2(x, y), new Vector2(x + LABEL_W, y), new Vector2(x + LABEL_W, y + LABEL_H), new Vector2(x, y + LABEL_H), }, isClosed: true); dxf.AddEntity(ent); } { var ent = new MText(txt) { Position = new Vector3(x + LABEL_W / 2, y + LABEL_H / 2, 0), Height = TXT_HEIGHT, RectangleWidth = LABEL_W, AttachmentPoint = MTextAttachmentPoint.MiddleCenter, Style = TXT_FONT }; dxf.AddEntity(ent); } x += LABEL_W; if ((i + 1) % COLS == 0) { y += LABEL_H; if (y >= ROWS * LABEL_H) { y = YORIGIN; ++page; } x = XORIGIN + page * (PAGE_W + LABEL_W); } } dxf.Save("output.dxf", isBinary: false); Process.Start(new ProcessStartInfo("output.dxf") { UseShellExecute = true }); }
private static void NestedBlock() { Block blockMM = new Block("BlockMM"); blockMM.Record.Units = DrawingUnits.Millimeters; AttributeDefinition attDefMM = new AttributeDefinition("MyAttributeMM"); attDefMM.Height = 1.0; attDefMM.Value = "This is block mm"; blockMM.AttributeDefinitions.Add(attDefMM); Line line1MM = new Line(Vector2.Zero, Vector2.UnitX); blockMM.Entities.Add(line1MM); Insert insMM = new Insert(blockMM); insMM.TransformAttributes(); Block blockCM = new Block("BlockCM"); blockCM.Record.Units = DrawingUnits.Centimeters; AttributeDefinition attDefCM = new AttributeDefinition("MyAttributeCM"); attDefCM.Height = 1.0; attDefCM.Value = "This is block cm"; blockCM.AttributeDefinitions.Add(attDefCM); Line line1CM = new Line(Vector2.Zero, Vector2.UnitY); blockCM.Entities.Add(line1CM); blockCM.Entities.Add(insMM); Insert insCM = new Insert(blockCM); DxfDocument doc = new DxfDocument(); doc.DrawingVariables.InsUnits = DrawingUnits.Meters; //doc.AddEntity(insMM); doc.AddEntity(insCM); doc.Save("test.dxf"); }
private static void SolidEntity() { // The solid vertexes are expressed in OCS (object coordinate system) // Now they are stored as Vector2 to force all vertexes to lay on a plane, this is similar as how the LwPolyline works. // The Z coordinate is controlled by the elevation property of the Solid. Vector2 a = new Vector2(-1, -1); Vector2 b = new Vector2(1, -1); Vector2 c = new Vector2(-1, 1); Vector2 d = new Vector2(1, 1); Solid solid = new Solid(a, b, c, d); solid.Normal = new Vector3(1, 1, 0); solid.Elevation = 2; DxfDocument doc = new DxfDocument(); doc.AddEntity(solid); doc.Save("SolidEntity.dxf"); }
static void doDXF(List<Polyline3dVertex> vertexes, double[] x) { // create a dxf for those who want to "see" the calibration DxfDocument dxf = new DxfDocument(); Polyline3d polyline = new Polyline3d(vertexes, true); polyline.Layer = new Layer("polyline3d"); polyline.Layer.Color.Index = 24; dxf.AddEntity(polyline); var pnt = new Point(new Vector3f(-(float) x[0], -(float) x[1], -(float) x[2])); pnt.Layer = new Layer("new offset"); pnt.Layer.Color.Index = 21; dxf.AddEntity(pnt); dxf.Save("magoffset.dxf", DxfVersion.AutoCad2000); log.Info("dxf Done " + DateTime.Now); }
/// <summary> /// 绘制左下角区域的Section块 /// </summary> /// <param name="dxf"></param> /// <param name="location"></param> /// <param name="configurations"></param> public static void Draw(DxfDocument dxf, Location location,SectionEntity sectionEntity) { float factor=0.6f; Vector3f v1 = new Vector3f(location.X, location.Y + 40.0f*factor, location.Z); Vector3f v2 = new Vector3f(location.X + 50.0f * factor, location.Y + 40.0f * factor, location.Z); Vector3f v3 = new Vector3f(location.X + 90.0f * factor, location.Y + 40.0f * factor, location.Z); Vector3f v4 = new Vector3f(location.X + 140.0f * factor, location.Y + 40.0f * factor, location.Z); Vector3f v5 = new Vector3f(location.X, location.Y + 50.0f * factor, location.Z); Vector3f v6 = new Vector3f(location.X + 140.0f * factor, location.Y + 50.0f * factor, location.Z); Vector3f v7 = new Vector3f(location.X, location.Y + 60.0f * factor, location.Z); Vector3f v8 = new Vector3f(location.X + 140.0f * factor, location.Y + 60.0f * factor, location.Z); Vector3f v9 = new Vector3f(location.X, location.Y + 70.0f * factor, location.Z); Vector3f v10 = new Vector3f(location.X + 50.0f * factor, location.Y + 70.0f * factor, location.Z); Vector3f v11 = new Vector3f(location.X + 90.0f * factor, location.Y + 70.0f * factor, location.Z); Vector3f v12 = new Vector3f(location.X + 140.0f * factor, location.Y + 70.0f * factor, location.Z); Layer layer = new Layer("line"); //横向四道 Line line14 = new Line(v1, v4); line14.Layer = layer; dxf.AddEntity(line14); Line line56 = new Line(v5, v6); line56.Layer = layer; dxf.AddEntity(line56); Line line78 = new Line(v7, v8); line78.Layer = layer; dxf.AddEntity(line78); Line line912 = new Line(v9, v12); line912.Layer = layer; dxf.AddEntity(line912); //纵向四道 Line line91 = new Line(v9, v1); line91.Layer = layer; dxf.AddEntity(line91); Line line210 = new Line(v2, v10); line210.Layer = layer; dxf.AddEntity(line210); Line line311 = new Line(v3, v11); line311.Layer = layer; dxf.AddEntity(line311); Line line412 = new Line(v4, v12); line412.Layer = layer; dxf.AddEntity(line412); TextStyle style = new TextStyle("True type font", "Arial.ttf"); Vector3f vt1 = new Vector3f(v1.X+1.0f, v1.Y+2.5f, v1.Z); Text t1 = new Text("COIL", vt1, 2.0f, style); t1.Layer = layer; t1.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t1); Vector3f vt2 = new Vector3f(v2.X + 1.0f, v2.Y + 2.5f, v2.Z); Text t2 = new Text("CLF", vt2, 2.0f, style); t2.Layer = layer; t2.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t2); Vector3f vt3 = new Vector3f(v3.X + 1.0f, v3.Y + 2.5f, v3.Z); Text t3 = new Text(sectionEntity.CoolValue, vt3, 2.0f, style); t3.Layer = layer; t3.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t3); Vector3f vt4 = new Vector3f(v5.X + 1.0f, v5.Y + 2.5f, v5.Z); Text t4 = new Text("FILTER", vt4, 2.0f, style); t4.Layer = layer; t4.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t4); Vector3f vt5 = new Vector3f(v2.X + 1.0f, v5.Y + 2.5f, v5.Z); Text t5 = new Text("FTA", vt5, 2.0f, style); t5.Layer = layer; t5.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t5); Vector3f vt6 = new Vector3f(v3.X + 1.0f, v5.Y + 2.5f, v5.Z); Text t6 = new Text(sectionEntity.FilterValue, vt6, 2.0f, style); t6.Layer = layer; t6.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t6); Vector3f vt7 = new Vector3f(v7.X + 1.0f, v7.Y + 2.5f, v7.Z); Text t7 = new Text("SECTION", vt7, 2.0f, style); t7.Layer = layer; t7.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t7); Vector3f vt8 = new Vector3f(v2.X + 1.0f, v7.Y + 2.5f, v7.Z); Text t8 = new Text("MODULE", vt8, 2.0f, style); t8.Layer = layer; t8.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t8); Vector3f vt9 = new Vector3f(v3.X + 1.0f, v7.Y + 2.5f, v7.Z); Text t9 = new Text("CLEARANCE", vt9, 2.0f, style); t9.Layer = layer; t9.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t9); }
public static void ModifyingGroups() { Line line1 = new Line(new Vector2(0, 0), new Vector2(100, 100)); line1.Color = AciColor.Red; Line line2 = new Line(new Vector2(100, 0), new Vector2(200, 100)); line2.Color = AciColor.Yellow; Line line3 = new Line(new Vector2(200, 0), new Vector2(300, 100)); line3.Color = AciColor.Magenta; DxfDocument doc = new DxfDocument(); Block blk = new Block("MyBlock"); blk.Entities.Add(line1); Insert ins = new Insert(blk); doc.AddEntity(ins); doc.AddEntity(line2); Layout layout = new Layout("Layout1"); doc.Layouts.Add(layout); doc.ActiveLayout = layout.Name; doc.AddEntity(line3); // group Group group = new Group("MyGroup"); doc.Groups.Add(group); // the Add method will also add the entities contained in a group to the document (in the active layout). doc.Groups.Add(group); // when the group belongs to a document, all entities must belong to the same document. // even if it does not sound very useful, a group can contain entities that belongs to different layouts and even blocks. group.Entities.Add(line1); group.Entities.Add(line2); group.Entities.Add(line3); Line line4 = new Line(new Vector2(300, 0), new Vector2(400, 100)); line4.Color = AciColor.Blue; // if a new entity, that does not belong to any document, is added to the group, it will be added to the group document active layout. doc.ActiveLayout = Layout.ModelSpaceName; group.Entities.Add(line4); Line line5 = new Line(new Vector2(400, 0), new Vector2(500, 100)); line5.Color = AciColor.Green; DxfDocument doc2 = new DxfDocument(); doc2.AddEntity(line5); // this is illegal, line5 belongs to another document. //group.Entities.Add(line5); // you need to clone the entity before adding it to the group. This is also the common practice to copy entities between documents. group.Entities.Add((EntityObject) line5.Clone()); // remember removing a group only deletes it from the collection not the entities //doc.Groups.Remove(group); doc.Save("group.dxf"); doc = DxfDocument.Load("group.dxf"); }
public static void ModifyingDocumentEntities() { Layer layer1 = new Layer("layer1"); Layer layer2 = new Layer("layer2"); Layer layer3 = new Layer("layer3"); LineType lineType1 = LineType.Dot; LineType lineType2 = LineType.Dashed; Line line = new Line(Vector2.Zero, Vector2.UnitX); line.Layer = layer1; line.LineType = lineType1; DxfDocument doc = new DxfDocument(); doc.AddEntity(line); // if the layer does not exist in the document it will be added automatically line.Layer = layer2; Debug.Assert(ReferenceEquals(line.Layer, doc.Layers[line.Layer.Name]), "References are not equal."); // you can always add it first doc.Layers.Add(layer3); // layer3 is defined in the document line.Layer = layer3; Debug.Assert(ReferenceEquals(line.Layer, doc.Layers[line.Layer.Name]), "References are not equal."); // same thing is applicable to line types line.LineType = lineType2; Debug.Assert(ReferenceEquals(line.LineType, doc.LineTypes[line.LineType.Name]), "References are not equal."); doc.Save("entity.dxf"); // it is also possible to rename table objects layer1.Name = "New layer1 name"; lineType1.Name = "DotDot"; // this operation is illegal, you cannot rename reserved table objects. //doc.Layers[Layer.DefaultName].Name = "NewName"; doc.Save("test.dxf"); }
public static void ModifyingBlockProperties() { DxfDocument doc = new DxfDocument(); doc.DrawingVariables.InsUnits = DrawingUnits.Centimeters; Line existingLine = new Line(new Vector2(-10, 10), new Vector2(10, -10)); doc.AddEntity(existingLine); AttributeDefinition attDef4 = new AttributeDefinition("MyAttribute4"); attDef4.Value = "MyValue4"; attDef4.Alignment = TextAlignment.TopCenter; Block block = new Block("MyBlock", null, new List<AttributeDefinition>{attDef4}); block.Record.Units = DrawingUnits.Millimeters; // this is incorrect we cannot add an entity that belongs to a document when the block does not belong to anyone. //block.Entities.Add(existingLine); doc.Blocks.Add(block); // when the block and the entity that is being added belong to the same document, the entity will be removed from its current layout and added to the block // you cannot add an entity that belongs to a different document or block. Clone it instead. block.Entities.Add(existingLine); // now we can modify the block properties even if it has been already added to the document Line line = new Line(new Vector2(-10, -10), new Vector2(10, 10)); // when new entities that do not belong to anyone are added to an existing block, they will also be added to the document block.Entities.Add(line); DxfDocument doc2 = new DxfDocument(); Circle circle = new Circle(Vector2.Zero, 5); doc2.AddEntity(circle); // this is incorrect the circle already belongs to another document //block.Entities.Add(circle); // we need to clone it first Circle circle2 = (Circle) circle.Clone(); circle2.Radius = 2.5; block.Entities.Add(circle2); //you could also remove circle2 from doc2 and add it to the block doc2.RemoveEntity(circle); block.Entities.Add(circle); AttributeDefinition attDef = new AttributeDefinition("MyAttribute1"); attDef.Value = "MyValue1"; block.AttributeDefinitions.Add(attDef); // the same that is applicable to entities is also true to attribute definitions AttributeDefinition attDef2 = new AttributeDefinition("MyAttribute2"); attDef2.Value = "MyValue2"; attDef2.Alignment = TextAlignment.BaselineRight; block.AttributeDefinitions.Add(attDef2); Insert ins = new Insert(block); doc.AddEntity(ins); // if the insert has been added to a document, any new attribute definitions added to the block will not be reflected in the insert // this mimics the behavior in AutoCad AttributeDefinition attDef3 = new AttributeDefinition("MyAttribute3"); attDef3.Value = "MyValue3"; attDef3.Alignment = TextAlignment.TopCenter; block.AttributeDefinitions.Add(attDef3); ins.Rotation = 30; // to update the insert attributes call the method Sync, this method will also call the method TransformAttributes ins.Sync(); // the ins2 will have all three attributes Insert ins2 = new Insert(block, new Vector2(20,0)); doc.AddEntity(ins2); doc.Save("Test.dxf"); block.Name = "MyBlockRenamed"; doc.Save("BlockRename.dxf"); doc = Test("BlockRename.dxf"); }
private static void RemoveBlock() { DxfDocument dxf = new DxfDocument(); Block block = new Block("MyBlock"); Line line1 = new Line(new Vector3(-5, -5, 0), new Vector3(5, 5, 0)); Line line2 = new Line(new Vector3(5, -5, 0), new Vector3(-5, 5, 0)); block.Entities.Add(line1); block.Entities.Add(line2); Insert insert = new Insert(block); dxf.AddEntity(insert); bool ok; // line1 is used by block and cannot be removed (ok = false) ok = dxf.RemoveEntity(line1); // block is used by insert and cannot be removed (ok = false) ok = dxf.Blocks.Remove(block); // it is safe to remove insert, it doesn't belong to anybody (ok = true) ok = dxf.RemoveEntity(insert); // it is safe to remove block, it doesn't belong to anybody (ok = true) // at the same time, all entities that were part of the block have been also removed ok = dxf.Blocks.Remove(block); // obj is null the line1 does not exist in the document, the block was removed DxfObject obj = dxf.GetObjectByHandle(line1.Handle); Console.WriteLine("Press a key..."); Console.ReadKey(); }
public static void DimensionUserText() { DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010); Vector3 p2 = new Vector3(0, 0, 0); Vector3 p1 = new Vector3(5, 0, 0); Line line1 = new Line(p1, p2) { Layer = new Layer("Reference line") { Color = AciColor.Green } }; dxf.AddEntity(line1); DimensionStyle style = new DimensionStyle("MyStyle"); double offset = 0.75; LinearDimension dim = new LinearDimension(line1, offset, 0, style); dim.UserText = null; // 5.00 (this is the default behavior) dxf.AddEntity(dim); dim = new LinearDimension(line1, 2 * offset, 0, style); dim.UserText = string.Empty; // 5.00 (same behavior as null) dxf.AddEntity(dim); dim = new LinearDimension(line1, 3 * offset, 0, style); dim.UserText = " "; // No dimension text will be drawn (one blank space) dxf.AddEntity(dim); dim = new LinearDimension(line1, 4 * offset, 0, style); dim.UserText = "<>"; // 5.00 (the characters <> will be substituted with the style.DIMPOST property) dxf.AddEntity(dim); dim = new LinearDimension(line1, 5 * offset, 0, style); dim.UserText = "Length: <> mm"; // Length: 5.00 mm (the characters <> will be substituted with the style.DIMPOST property) dxf.AddEntity(dim); dim = new LinearDimension(line1, 6 * offset, 0, style); dim.UserText = "User text"; // User text dxf.AddEntity(dim); dxf.Save("DimensionUserText.dxf"); }
public static void DimensionsLinearAndAngularUnits() { DimensionStyle style = new DimensionStyle("MyStyle") { // DIMDEC defines the number of decimal places. // For Architectural and Fractional units the minimum fraction is defined by 1/2^DIMDEC. DIMDEC = 4, DIMFRAC = FractionFormatType.Horizontal, DIMLUNIT = LinearUnitType.Engineering, SuppressLinearTrailingZeros = true, SuppressZeroFeet = false, SuppressZeroInches = false, DIMLFAC = 10.0, // the round off to nearest DIMRND is applied to the linear dimension measurement after applying the scale DIMLFAC DIMRND = 0.025, DIMADEC = 2, DIMAUNIT = AngleUnitType.DegreesMinutesSeconds }; Layer layer = new Layer("Layer1") { Color = AciColor.Blue }; Vector3 p1 = new Vector3(0, 0, 0); Vector3 p2 = new Vector3(21.2548, 0, 0); LinearDimension dim = new LinearDimension(p1, p2, 4, 0, style); Vector2 s1 = new Vector2(-2, 2); Vector2 s2 = new Vector2(2, -2); Vector2 e1 = new Vector2(-1, -3); Vector2 e2 = new Vector2(1, 3); Line line1 = new Line(s1, s2) { Layer = layer }; Line line2 = new Line(e1, e2) { Layer = layer }; Angular2LineDimension dim1 = new Angular2LineDimension(line2, line1, 4, style); DxfDocument doc = new DxfDocument(); doc.AddEntity(dim); doc.AddEntity(dim1); doc.Save("DimensionsLinearAndAngularUnits.dxf"); DxfDocument dxf = DxfDocument.Load("DimensionsLinearAndAngularUnits.dxf"); }
public static void ModifyingMLineStyles() { DxfDocument doc = new DxfDocument(DxfVersion.AutoCad2010); doc.DrawingVariables.LtScale = 10; List<Vector2> vertexes = new List<Vector2> { new Vector2(0, 0), new Vector2(0, 150), new Vector2(150, 150), new Vector2(150, 0) }; MLine mline = new MLine(vertexes); mline.Scale = 20; mline.Justification = MLineJustification.Zero; MLineStyle style = new MLineStyle("MyStyle", "Personalized style."); style.Elements.Add(new MLineStyleElement(0.25)); style.Elements.Add(new MLineStyleElement(-0.25)); // if we add new elements directly to the list we need to sort the list, style.Elements.Sort(); style.Flags = MLineStyleFlags.EndInnerArcsCap | MLineStyleFlags.EndRoundCap | MLineStyleFlags.StartInnerArcsCap | MLineStyleFlags.StartRoundCap; // AutoCad2000 dxf version does not support true colors for MLineStyle elements style.Elements[0].Color = new AciColor(180, 230, 147); doc.AddEntity(mline); // change the multi line style after it has been added to the document mline.Style = style; Debug.Assert(ReferenceEquals(mline.Style, doc.MlineStyles[mline.Style.Name]), "Reference not equals."); // VERY IMPORTANT: We have modified the MLine after setting its vertexes so we need to manually call this method. // It is also necessary when manually editing the vertex distances. mline.Update(); // the line type will be automatically added to the document foreach (MLineStyleElement e in style.Elements) { // making changes after the MLineStyle has been added to the document e.LineType = LineType.Dashed; Debug.Assert(ReferenceEquals(e.LineType, doc.LineTypes[e.LineType.Name]), "Reference not equals."); } MLine copy = (MLine) mline.Clone(); copy.Scale = 100; doc.AddEntity(copy); // once the entity has been added to the document, changing its style requires that the new style is also present in the document. copy.Style = doc.MlineStyles["standard"]; // VERY IMPORTANT: We have modified the MLine after setting its vertexes so we need to manually call this method. // It is also necessary when manually editing the vertex distances. copy.Update(); doc.Save("ModifyingMLineStyle.dxf"); Test("ModifyingMLineStyle.dxf"); }
private void DrawRectangleInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Core2D.BaseStyle style, ref Core2D.Rect2 rect) { double x = rect.X; double y = rect.Y; double w = rect.Width; double h = rect.Height; var dxfLine1 = CreateLine(x, y, x + w, y); var dxfLine2 = CreateLine(x + w, y, x + w, y + h); var dxfLine3 = CreateLine(x + w, y + h, x, y + h); var dxfLine4 = CreateLine(x, y + h, x, y); if (isFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); var bounds = new List <HatchBoundaryPath> { new HatchBoundaryPath( new List <EntityObject> { (Line)dxfLine1.Clone(), (Line)dxfLine2.Clone(), (Line)dxfLine3.Clone(), (Line)dxfLine4.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; doc.AddEntity(hatch); } if (isStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfLine1.Layer = layer; dxfLine1.Color = stroke; dxfLine1.Transparency.Value = strokeTansparency; dxfLine1.Lineweight.Value = lineweight; dxfLine2.Layer = layer; dxfLine2.Color = stroke; dxfLine2.Transparency.Value = strokeTansparency; dxfLine2.Lineweight.Value = lineweight; dxfLine3.Layer = layer; dxfLine3.Color = stroke; dxfLine3.Transparency.Value = strokeTansparency; dxfLine3.Lineweight.Value = lineweight; dxfLine4.Layer = layer; dxfLine4.Color = stroke; dxfLine4.Transparency.Value = strokeTansparency; dxfLine4.Lineweight.Value = lineweight; doc.AddEntity(dxfLine1); doc.AddEntity(dxfLine2); doc.AddEntity(dxfLine3); doc.AddEntity(dxfLine4); } }
private void DrawRectangleInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect) { double x = rect.X; double y = rect.Y; double w = rect.Width; double h = rect.Height; var dxfLine1 = CreateLine(x, y, x + w, y); var dxfLine2 = CreateLine(x + w, y, x + w, y + h); var dxfLine3 = CreateLine(x + w, y + h, x, y + h); var dxfLine4 = CreateLine(x, y + h, x, y); if (isFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Line)dxfLine1.Clone(), (Line)dxfLine2.Clone(), (Line)dxfLine3.Clone(), (Line)dxfLine4.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; doc.AddEntity(hatch); } if (isStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfLine1.Layer = layer; dxfLine1.Color = stroke; dxfLine1.Transparency.Value = strokeTansparency; dxfLine1.Lineweight.Value = lineweight; dxfLine2.Layer = layer; dxfLine2.Color = stroke; dxfLine2.Transparency.Value = strokeTansparency; dxfLine2.Lineweight.Value = lineweight; dxfLine3.Layer = layer; dxfLine3.Color = stroke; dxfLine3.Transparency.Value = strokeTansparency; dxfLine3.Lineweight.Value = lineweight; dxfLine4.Layer = layer; dxfLine4.Color = stroke; dxfLine4.Transparency.Value = strokeTansparency; dxfLine4.Lineweight.Value = lineweight; doc.AddEntity(dxfLine1); doc.AddEntity(dxfLine2); doc.AddEntity(dxfLine3); doc.AddEntity(dxfLine4); } }
public static void ModifyingDimensionGeometryAndStyle() { DimensionStyle style = new DimensionStyle("MyStyle"); Vector3 p1 = new Vector3(-2.5, 0, 0); Vector3 p2 = new Vector3(2.5, 0, 0); LinearDimension dim = new LinearDimension(p1, p2, 4, 0, style); // This is illegal. Trying to rebuild the dimension block before it has been added to a document will throw an exception //dim.RebuildBlock(); DxfDocument doc = new DxfDocument(); doc.AddEntity(dim); // modifying the dimension style dim.Style.DIMBLK = DimensionArrowhead.ArchitecturalTick; // if we make any change to the dimension style, we need to manually call the RebuildBlock method to reflect the new changes // since we will also modify the geometry of the dimension we will rebuild the block latter //dim.RebuildBlock(); // the same kind of procedure needs to be done when modifying the geometry of a dimension dim.FirstReferencePoint = new Vector3(-5.0, 0, 0); dim.SecondReferencePoint = new Vector3(5.0, 0, 0); // now that all necessary changes has been made, we will rebuild the block. // this is an expensive operation, use it only when need it. dim.Style.DIMBLK = DimensionArrowhead.Box; dim.Style.DIMBLK = DimensionArrowhead.ArchitecturalTick; Debug.Assert(ReferenceEquals(dim.Style.DIMBLK, doc.Blocks[dim.Style.DIMBLK.Name]), "References are not equal."); Debug.Assert(ReferenceEquals(style.DIMBLK, doc.Blocks[style.DIMBLK.Name]), "References are not equal."); //dim.Style.DIMBLK = null; // VERY IMPORTANT: If any change is made to the dimension geometry and/or its style, we need to rebuild the drawing representation // so the dimension block will reflect the new changes. This is only necessary for dimension that already belongs to a document. // This process is automatically called when a new dimension is added to a document. dim.Update(); Debug.Assert(ReferenceEquals(dim.Block, doc.Blocks[dim.Block.Name])); doc.Save("dimension.dxf"); Test("dimension.dxf"); }
/// <summary> /// 绘制订单信息块 /// </summary> /// <param name="dxf"></param> /// <param name="location"></param> /// <param name="boxWidth"></param> /// <param name="configurations"></param> public static void Draw(DxfDocument dxf, Location location,float boxWidth, OrderEntity orderEntity) { float factor = 0.6f; Vector3f v1 = new Vector3f(location.X,location.Y,location.Z); Vector3f v2 = new Vector3f(location.X + boxWidth, location.Y, location.Z); Vector3f v3 = new Vector3f(location.X + boxWidth, location.Y + 40.0f * factor, location.Z); Vector3f v4 = new Vector3f(location.X, location.Y + 40.0f * factor, location.Z); Vector3f v5 = new Vector3f(location.X, location.Y + 10.0f * factor, location.Z); Vector3f v6 = new Vector3f(location.X + boxWidth / 4, location.Y + 10.0f * factor, location.Z); Vector3f v7 = new Vector3f(location.X + boxWidth / 2, location.Y + 10.0f * factor, location.Z); Vector3f v8 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 10.0f * factor, location.Z); Vector3f v9 = new Vector3f(location.X + boxWidth * 7 / 8, location.Y + 10.0f * factor, location.Z); Vector3f v10 = new Vector3f(location.X + boxWidth / 4, location.Y + 20.0f * factor, location.Z); Vector3f v11 = new Vector3f(location.X + boxWidth / 2, location.Y + 20.0f * factor, location.Z); Vector3f v12 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 20.0f * factor, location.Z); Vector3f v13 = new Vector3f(location.X + boxWidth * 7 / 8, location.Y + 20.0f * factor, location.Z); Vector3f v14 = new Vector3f(location.X + boxWidth, location.Y + 20.0f * factor, location.Z); Vector3f v15 = new Vector3f(location.X + boxWidth / 4, location.Y + 40.0f * factor, location.Z); Vector3f v16 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 40.0f * factor, location.Z); Vector3f v17 = new Vector3f(location.X + boxWidth / 4, location.Y, location.Z); Vector3f v18 = new Vector3f(location.X + boxWidth / 2, location.Y, location.Z); Vector3f v19 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y, location.Z); Vector3f v20 = new Vector3f(location.X + boxWidth, location.Y + 10.0f * factor, location.Z); Layer layer = new Layer("line"); //横向四道 Line line12 = new Line(v1, v2); line12.Layer = layer; dxf.AddEntity(line12); Line line520 = new Line(v5, v20); line520.Layer = layer; dxf.AddEntity(line520); Line line1014 = new Line(v10, v14); line1014.Layer = layer; dxf.AddEntity(line1014); Line line43 = new Line(v4, v3); line43.Layer = layer; dxf.AddEntity(line43); //纵向6道 Line line41 = new Line(v4, v1); line41.Layer = layer; dxf.AddEntity(line41); Line line1517 = new Line(v15, v17); line1517.Layer = layer; dxf.AddEntity(line1517); Line line1118 = new Line(v11, v18); line1118.Layer = layer; dxf.AddEntity(line1118); Line line1619 = new Line(v16, v19); line1619.Layer = layer; dxf.AddEntity(line1619); Line line139 = new Line(v13, v9); line139.Layer = layer; dxf.AddEntity(line139); Line line32= new Line(v3, v2); line32.Layer = layer; dxf.AddEntity(line32); //文字 TextStyle style = new TextStyle("True type font", "Arial.ttf"); Vector3f vt1 = new Vector3f(v1.X + 1.0f, v1.Y + 2.5f, v1.Z); Text t1 = new Text("Celebrity 1.0.0", vt1, 2.0f, style); t1.Layer = layer; t1.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t1); Vector3f vt2 = new Vector3f(v17.X + 1.0f, v17.Y + 2.5f, v1.Z); Text t2 = new Text("PREPARER: "+orderEntity.Preparer, vt2, 2.0f, style); t2.Layer = layer; t1.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t2); Vector3f vt3 = new Vector3f(v18.X + 1.0f, v18.Y + 2.5f, v1.Z); Text t3 = new Text("ENGINEER: "+orderEntity.Engineer, vt3, 2.0f, style); t3.Layer = layer; t3.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t3); Vector3f vt4 = new Vector3f(v19.X + 1.0f, v19.Y + 2.5f, v1.Z); Text t4 = new Text("SHIP ORDER NO: "+orderEntity.ShipOrderNo, vt4, 2.0f, style); t4.Layer = layer; t4.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t4); Vector3f vt5 = new Vector3f(v4.X + 1.0f, v10.Y + 2.5f, v1.Z); Text t5= new Text(" AAON COIL PRODUCTS inc.", vt5, 3.0f, style); t5.Layer = layer; t5.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t5); Vector3f vt6 = new Vector3f(v5.X + 1.0f, v5.Y + 2.5f, v1.Z); Text t6 = new Text("LONGVIEW TEXAS", vt6, 2.0f, style); t6.Layer = layer; t6.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t6); Vector3f vt7 = new Vector3f(v6.X + 1.0f, v6.Y + 2.5f, v1.Z); Text t7 = new Text("PURCHASER: " + orderEntity.Purchaser, vt7, 2.0f, style); t7.Layer = layer; t7.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t7); Vector3f vt8 = new Vector3f(v7.X + 1.0f, v7.Y + 2.5f, v1.Z); Text t8 = new Text("PURCHASE ORDER: " + orderEntity.PurchaseOrder, vt8, 2.0f, style); t8.Layer = layer; t8.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t8); Vector3f vt9 = new Vector3f(v8.X + 1.0f, v8.Y + 2.5f, v1.Z); Text t9 = new Text("SERIAL NO: " + orderEntity.SeriaNo, vt9, 2.0f, style); t9.Layer = layer; t9.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t9); Vector3f vt10 = new Vector3f(v9.X + 1.0f, v9.Y + 2.5f, v1.Z); Text t10 = new Text("DATE: "+DateTime.Now.ToShortDateString(), vt10, 2.0f, style); t10.Layer = layer; t10.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t10); Vector3f vt11 = new Vector3f(v15.X + 1.0f, v15.Y - 7.5f, v1.Z); Text t11 = new Text("JOB NAME:", vt11, 2.0f, style); t11.Layer = layer; t11.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t11); Vector3f vt12 = new Vector3f(v10.X + 10.0f, v10.Y + 2.5f, v1.Z); Text t12 = new Text(orderEntity.JobName, vt12, 2.0f, style); t12.Layer = layer; t12.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t12); Vector3f vt13 = new Vector3f(v16.X + 1.0f, v16.Y - 7.5f, v1.Z); Text t13 = new Text("UNIT TAG:", vt13, 2.0f, style); t13.Layer = layer; t13.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t13); Vector3f vt14 = new Vector3f(v12.X + 20.0f, v12.Y + 2.5f, v1.Z); Text t14 = new Text(orderEntity.UnitTag, vt14, 2.0f, style); t14.Layer = layer; t14.Alignment = TextAlignment.TopLeft; dxf.AddEntity(t14); }
//画标注 public static void writeDimension(DxfDocument doc,Location firstLocation,Location secondLocation,float textHeight,float textWidth,float dimensionHeight,string dimensionDirection) { float numWidth; string strNumWidth = ""; Layer dimensionLayer=new Layer("dimensionLayer"); Line line1 = new Line(); Line line2 = new Line(); Line leftLine = new Line(); Line rightLine = new Line(); Line upLeftLine = new Line(); Line downLeftLine = new Line(); Line upRightLine = new Line(); Line downRightLine = new Line(); Text strText = new Text(); line1.Layer = dimensionLayer; line2.Layer = dimensionLayer; leftLine.Layer = dimensionLayer; rightLine.Layer = dimensionLayer; upLeftLine.Layer = dimensionLayer; downLeftLine.Layer = dimensionLayer; upRightLine.Layer = dimensionLayer; downRightLine.Layer = dimensionLayer; strText.Layer = dimensionLayer; if (dimensionDirection.Equals("top")) { line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z); line1.EndPoint = new Vector3f(firstLocation.X, firstLocation.Y + dimensionHeight, firstLocation.Z); line2.StartPoint = new Vector3f(secondLocation.X,secondLocation.Y,secondLocation.Z); line2.EndPoint = new Vector3f(secondLocation.X,secondLocation.Y+dimensionHeight,secondLocation.Z); leftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y + 7 * dimensionHeight / 8,firstLocation.Z); leftLine.EndPoint = new Vector3f(firstLocation.X+Math.Abs(firstLocation.X-secondLocation.X)/2-textWidth/2,firstLocation.Y+7*dimensionHeight/8, firstLocation.Z); upLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y + 7 * dimensionHeight / 8,firstLocation.Z); upLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y + 7 * dimensionHeight / 8+0.2f,firstLocation.Z); downLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y + 7 * dimensionHeight / 8, firstLocation.Z); downLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y + 7 * dimensionHeight / 8 - 0.2f, firstLocation.Z); upRightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y + 7 * dimensionHeight/8,secondLocation.Z); upRightLine.EndPoint = new Vector3f(secondLocation.X - 0.2f, secondLocation.Y + 7 * dimensionHeight / 8 + 0.2f, secondLocation.Z); downRightLine.StartPoint = new Vector3f(secondLocation.X,secondLocation.Y+7*dimensionHeight/8,secondLocation.Z); downRightLine.EndPoint = new Vector3f(secondLocation.X-0.2f,secondLocation.Y+7*dimensionHeight/8-0.2f,secondLocation.Z); rightLine.StartPoint = new Vector3f(secondLocation.X,secondLocation.Y+7*dimensionHeight/8,secondLocation.Z); rightLine.EndPoint = new Vector3f(secondLocation.X-Math.Abs(firstLocation.X-secondLocation.X)/2+textWidth/2,secondLocation.Y+7*dimensionHeight/8,secondLocation.Z); numWidth = secondLocation.X - firstLocation.X; strNumWidth = "" + numWidth; strText.BasePoint=new Vector3f(firstLocation.X+Math.Abs(firstLocation.X-secondLocation.X)/2-textWidth/2+0.2f,firstLocation.Y+7*dimensionHeight/8, firstLocation.Z); strText.Height=0.5f; strText.Value=strNumWidth; } else if(dimensionDirection.Equals("bottom")){ line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z); line1.EndPoint = new Vector3f(firstLocation.X, firstLocation.Y - dimensionHeight, firstLocation.Z); line2.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y, secondLocation.Z); line2.EndPoint = new Vector3f(secondLocation.X, secondLocation.Y - dimensionHeight, secondLocation.Z); leftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z); leftLine.EndPoint = new Vector3f(firstLocation.X + Math.Abs(firstLocation.X - secondLocation.X) / 2 - textWidth / 2, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z); upLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z); upLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y - 7 * dimensionHeight / 8 + 0.2f, firstLocation.Z); downLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z); downLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y - 7 * dimensionHeight / 8 - 0.2f, firstLocation.Z); upRightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z); upRightLine.EndPoint = new Vector3f(secondLocation.X - 0.2f, secondLocation.Y - 7 * dimensionHeight / 8 + 0.2f, secondLocation.Z); downRightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z); downRightLine.EndPoint = new Vector3f(secondLocation.X - 0.2f, secondLocation.Y - 7 * dimensionHeight / 8 - 0.2f, secondLocation.Z); rightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z); rightLine.EndPoint = new Vector3f(secondLocation.X - Math.Abs(firstLocation.X - secondLocation.X) / 2 + textWidth / 2, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z); numWidth = secondLocation.X - firstLocation.X; strNumWidth = "" + numWidth; strText.BasePoint=new Vector3f(firstLocation.X+Math.Abs(firstLocation.X-secondLocation.X)/2-textWidth/2+0.2f,firstLocation.Y-7*dimensionHeight/8, firstLocation.Z); strText.Height=0.5f; strText.Value=strNumWidth; } else if(dimensionDirection.Equals("left")){ line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z); line1.EndPoint = new Vector3f(firstLocation.X - dimensionHeight, firstLocation.Y, firstLocation.Z); line2.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y, secondLocation.Z); line2.EndPoint = new Vector3f(secondLocation.X - dimensionHeight, secondLocation.Y, secondLocation.Z); leftLine.StartPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z); leftLine.EndPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2, firstLocation.Z); upLeftLine.StartPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z); upLeftLine.EndPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8 - 0.2f, firstLocation.Y + 0.2f, firstLocation.Z); downLeftLine.StartPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z); downLeftLine.EndPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8 + 0.2f, firstLocation.Y+0.2f, firstLocation.Z); upRightLine.StartPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z); upRightLine.EndPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8 - 0.2f, secondLocation.Y - 0.2f, secondLocation.Z); downRightLine.StartPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z); downRightLine.EndPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8 + 0.2f, secondLocation.Y-0.2f, secondLocation.Z); rightLine.StartPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z); rightLine.EndPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y - Math.Abs(firstLocation.Y - secondLocation.Y) / 2 + textWidth / 2, secondLocation.Z); numWidth = secondLocation.Y - firstLocation.Y; strNumWidth = "" + numWidth; strText.BasePoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2 + 0.2f, firstLocation.Z); strText.Height=0.5f; strText.Value=strNumWidth; } else if (dimensionDirection.Equals("right")) { line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z); line1.EndPoint = new Vector3f(firstLocation.X + dimensionHeight, firstLocation.Y, firstLocation.Z); line2.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y, secondLocation.Z); line2.EndPoint = new Vector3f(secondLocation.X + dimensionHeight, secondLocation.Y, secondLocation.Z); leftLine.StartPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z); leftLine.EndPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2, firstLocation.Z); upLeftLine.StartPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z); upLeftLine.EndPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8 - 0.2f, firstLocation.Y + 0.2f, firstLocation.Z); downLeftLine.StartPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z); downLeftLine.EndPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8 + 0.2f, firstLocation.Y + 0.2f, firstLocation.Z); upRightLine.StartPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z); upRightLine.EndPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8 - 0.2f, secondLocation.Y - 0.2f, secondLocation.Z); downRightLine.StartPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z); downRightLine.EndPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8 + 0.2f, secondLocation.Y - 0.2f, secondLocation.Z); rightLine.StartPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z); rightLine.EndPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y - Math.Abs(firstLocation.Y - secondLocation.Y) / 2 + textWidth / 2, secondLocation.Z); numWidth = secondLocation.Y - firstLocation.Y; strNumWidth = "" + numWidth; strText.BasePoint=new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2+0.2f, firstLocation.Z); strText.Height=0.5f; strText.Value=strNumWidth; } doc.AddEntity(line1); doc.AddEntity(line2); doc.AddEntity(leftLine); doc.AddEntity(rightLine); doc.AddEntity(upLeftLine); doc.AddEntity(downLeftLine); doc.AddEntity(upRightLine); doc.AddEntity(downRightLine); doc.AddEntity(strText); }
public void WriteProject(WaveguideDesignerProjectData project) { if( project == null ) return; Type type; EntityObject obj = null; DxfDocument doc = new DxfDocument(); doc.Name = project.Name; Layer dxfLayer; LayerData layerData; foreach( VirtualLayer vLayer in project.VirtualGraphics.Layers ) { layerData = null; foreach( LayerData tmp in project.Layers ) if( tmp.VirtualLayer == vLayer ) { layerData = tmp; break; } if( layerData == null ) continue; dxfLayer = new Layer( layerData.Name ); dxfLayer.Color.Index = (short)layerData.LayerNumber; doc.Layers.Add( dxfLayer ); foreach( VirtualShapeBase vShape in vLayer.Shapes ) { type = vShape.GetType(); if( type == typeof( VirtualRectangle ) ) { VirtualRectangle rect = (VirtualRectangle)vShape; Polyline dxfrect = new Polyline(); obj = new Polyline(); dxfrect.IsClosed = true; dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X + rect.Size.W, rect.Location.Y, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X + rect.Size.W, rect.Location.Y + rect.Size.H, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y + rect.Size.H, 0 ) ); dxfrect.Vertexes.Add( new PolylineVertex( rect.Location.X, rect.Location.Y, 0 ) ); obj = dxfrect; } else if( type == typeof( VirtualPolygon ) ) { VirtualPolygon poly = (VirtualPolygon)vShape; Polyline dxfpoly = new Polyline(); dxfpoly.IsClosed = true; foreach( PointD p in poly.Vertices ) dxfpoly.Vertexes.Add( conv( p ) ); dxfpoly.Vertexes.Add( conv( poly.Vertices[0] ) ); obj = dxfpoly; } else if( type == typeof( VirtualEllipse ) ) { VirtualEllipse elli = (VirtualEllipse)vShape; Ellipse dxfelli = new Ellipse(); dxfelli.Center = new netDxf.Vector3( elli.Center.X, elli.Center.Y, 0 ); dxfelli.StartAngle = 0; dxfelli.EndAngle = 360; dxfelli.MajorAxis = Math.Max( elli.Radius.W, elli.Radius.H ); dxfelli.MinorAxis = Math.Min( elli.Radius.W, elli.Radius.H ); dxfelli.Rotation = elli.Radius.W >= elli.Radius.H ? 0 : 90; obj = dxfelli; } else if( type == typeof( VirtualPie ) ) { VirtualPie pie = (VirtualPie)vShape; Ellipse dxfelli = new Ellipse(); dxfelli.Center = new netDxf.Vector3( pie.Center.X, pie.Center.Y, 0 ); dxfelli.StartAngle = pie.StartAngle; dxfelli.EndAngle = pie.EndAngle; dxfelli.MajorAxis = Math.Max( pie.Radius.W, pie.Radius.H ); dxfelli.MinorAxis = Math.Min( pie.Radius.W, pie.Radius.H ); dxfelli.Rotation = pie.Radius.W >= pie.Radius.H ? 0 : 90; obj = dxfelli; } else obj = null; if( obj == null ) continue; obj.Layer = dxfLayer; doc.AddEntity( obj ); } } doc.Save( FileName ); }
//画无门栓的矩形框 public static void writeDoorRectangle(DxfDocument doc, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space) { Layer doorRectangleLayer = new Layer("nonDoorBarLayer"); //最外围矩形 writeOuterDoorRectangle(doc,location,height,width); //中间矩形 Line midBottomLine=new Line(new Vector3f(location.X+outer_mid_space,location.Y+outer_mid_space,location.Z),new Vector3f(location.X+width-outer_mid_space,location.Y+outer_mid_space,location.Z)); midBottomLine.Layer=doorRectangleLayer; Line midLeftLine=new Line(new Vector3f(location.X+outer_mid_space,location.Y+outer_mid_space,location.Z),new Vector3f(location.X+outer_mid_space,location.Y+height-outer_mid_space,location.Z)); midLeftLine.Layer=doorRectangleLayer; Line midTopLine=new Line(new Vector3f(location.X+outer_mid_space,location.Y+height-outer_mid_space,location.Z),new Vector3f(location.X+width-outer_mid_space,location.Y+height-outer_mid_space,location.Z)); midTopLine.Layer=doorRectangleLayer; Line midRightLine = new Line(new Vector3f(location.X + width - outer_mid_space, location.Y + height - outer_mid_space, location.Z), new Vector3f(location.X + width - outer_mid_space, location.Y + outer_mid_space, location.Z)); midRightLine.Layer = doorRectangleLayer; doc.AddEntity(midBottomLine); doc.AddEntity(midLeftLine); doc.AddEntity(midTopLine); doc.AddEntity(midRightLine); //内部矩形 Line inBottomLine = new Line(new Vector3f(location.X + outer_in_space, location.Y + outer_in_space, location.Z), new Vector3f(location.X + width - outer_in_space, location.Y + outer_in_space, location.Z)); inBottomLine.Layer = doorRectangleLayer; Line inLeftLine = new Line(new Vector3f(location.X + outer_in_space, location.Y + outer_in_space, location.Z), new Vector3f(location.X + outer_in_space, location.Y + height - outer_in_space, location.Z)); inLeftLine.Layer = doorRectangleLayer; Line inTopLine = new Line(new Vector3f(location.X + outer_in_space, location.Y + height - outer_in_space, location.Z), new Vector3f(location.X + width - outer_in_space, location.Y + height - outer_in_space, location.Z)); inTopLine.Layer = doorRectangleLayer; Line inRightLine = new Line(new Vector3f(location.X + width - outer_in_space, location.Y + height - outer_in_space, location.Z), new Vector3f(location.X + width - outer_in_space, location.Y + outer_in_space, location.Z)); inRightLine.Layer = doorRectangleLayer; doc.AddEntity(inBottomLine); doc.AddEntity(inLeftLine); doc.AddEntity(inTopLine); doc.AddEntity(inRightLine); //门中文字 float textHeight=DoorInitHeightAndWidth.textHeight; for(int i=0;i<text.Length;i++){ Text doorRectangleText = new Text(text[i], new Vector3f(location.X + width / 3, location.Y + 3*height / 4- i * textHeight, location.Z), textHeight); doorRectangleText.Layer = doorRectangleLayer; doc.AddEntity(doorRectangleText); } }
private void DrawGridInternal(DxfDocument doc, Layer layer, Test2d.ShapeStyle style, double offsetX, double offsetY, double cellWidth, double cellHeight, ref Test2d.Rect2 rect) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); double ox = rect.X; double oy = rect.Y; double sx = ox + offsetX; double sy = oy + offsetY; double ex = ox + rect.Width; double ey = oy + rect.Height; for (double gx = sx; gx < ex; gx += cellWidth) { var dxfLine = CreateLine(gx, oy, gx, ey); dxfLine.Layer = layer; dxfLine.Color = stroke; dxfLine.Transparency.Value = strokeTansparency; dxfLine.Lineweight.Value = lineweight; doc.AddEntity(dxfLine); } for (double gy = sy; gy < ey; gy += cellHeight) { var dxfLine = CreateLine(ox, gy, ex, gy); dxfLine.Layer = layer; dxfLine.Color = stroke; dxfLine.Transparency.Value = strokeTansparency; dxfLine.Lineweight.Value = lineweight; doc.AddEntity(dxfLine); } }
//画两个门有门闩的设备 public static void writeDoubleDoorBarRectangle(DxfDocument doc, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space,float barHeight,float barWidth) { Layer doorLineLayer = new Layer("DoubleDoorBarRectangle"); Line outerLeftLine = new Line(new Vector3f(location.X + width / 2 - width / 14, location.Y + outer_mid_space, location.Z), new Vector3f(location.X + width / 2 - width / 14, location.Y + height - outer_mid_space, location.Z)); outerLeftLine.Layer = doorLineLayer; Line inLeftLine = new Line(new Vector3f(location.X + width / 2 - width / 14 + 0.5f, location.Y + outer_in_space, location.Z), new Vector3f(location.X + width / 2 - width / 14 + 0.5f, location.Y + height - outer_in_space, location.Z)); inLeftLine.Layer = doorLineLayer; Line inDownRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14, location.Y + outer_in_space, location.Z), new Vector3f(location.X + width / 2 + width / 14, location.Y + height/4, location.Z)); inDownRightLine.Layer = doorLineLayer; Line inMidRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14, location.Y + height / 4 + barHeight, location.Z), new Vector3f(location.X + width / 2 + width / 14, location.Y + 3 * height / 4 - barHeight, location.Z)); inMidRightLine.Layer = doorLineLayer; Line inUpRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14, location.Y + 3*height / 4, location.Z), new Vector3f(location.X + width / 2 + width / 14, location.Y + height-outer_in_space, location.Z)); inUpRightLine.Layer = doorLineLayer; Line outerDownRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + outer_mid_space, location.Z), new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + height/4, location.Z)); outerDownRightLine.Layer = doorLineLayer; Line outerMidRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + height/4+barHeight, location.Z), new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + 3*height / 4-barHeight, location.Z)); outerMidRightLine.Layer = doorLineLayer; Line outerUpRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + 3*height / 4, location.Z), new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + height-outer_in_space, location.Z)); outerUpRightLine.Layer = doorLineLayer; doc.AddEntity(outerLeftLine); doc.AddEntity(inLeftLine); doc.AddEntity(inDownRightLine); doc.AddEntity(inMidRightLine); doc.AddEntity(inUpRightLine); doc.AddEntity(outerDownRightLine); doc.AddEntity(outerMidRightLine); doc.AddEntity(outerUpRightLine); writeDoorBarRectangle(doc, location, text, height, width, outer_mid_space, outer_in_space,barHeight,barWidth); }
private void DrawEllipseInternal(DxfDocument doc, Layer layer, bool isFilled, bool isStroked, Test2d.BaseStyle style, ref Test2d.Rect2 rect) { var dxfEllipse = CreateEllipse(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { var fill = GetColor(style.Fill); var fillTransparency = GetTransparency(style.Fill); // TODO: The netDxf does not create hatch for Ellipse with end angle equal to 360. var bounds = new List<HatchBoundaryPath> { new HatchBoundaryPath( new List<EntityObject> { (Ellipse)dxfEllipse.Clone() }) }; var hatch = new Hatch(HatchPattern.Solid, bounds, false); hatch.Layer = layer; hatch.Color = fill; hatch.Transparency.Value = fillTransparency; doc.AddEntity(hatch); } if (isStroked) { var stroke = GetColor(style.Stroke); var strokeTansparency = GetTransparency(style.Stroke); var lineweight = ThicknessToLineweight(style.Thickness); dxfEllipse.Layer = layer; dxfEllipse.Color = stroke; dxfEllipse.Transparency.Value = strokeTansparency; dxfEllipse.Lineweight.Value = lineweight; doc.AddEntity(dxfEllipse); } }
//画两个门无门闩的设备 public static void writeDoubleDoorRectangle(DxfDocument doc,Location location,string [] text,float height,float width,float outer_mid_space,float outer_in_space) { Layer doorLineLayer=new Layer("doorLineLayer"); Line outerLeftLine=new Line(new Vector3f(location.X+width/2-width/14,location.Y+outer_mid_space,location.Z),new Vector3f(location.X+width/2-width/14,location.Y+height-outer_mid_space,location.Z)); outerLeftLine.Layer = doorLineLayer; Line inLeftLine = new Line(new Vector3f(location.X + width / 2 - width / 14 + 0.5f, location.Y + outer_in_space, location.Z), new Vector3f(location.X + width / 2 - width / 14 + 0.5f, location.Y + height - outer_in_space, location.Z)); inLeftLine.Layer = doorLineLayer; Line inRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14, location.Y + outer_in_space, location.Z), new Vector3f(location.X + width / 2 + width / 14, location.Y + height - outer_in_space, location.Z)); inRightLine.Layer = doorLineLayer; Line outerRightLine = new Line(new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + outer_mid_space, location.Z), new Vector3f(location.X + width / 2 + width / 14 + 0.5f, location.Y + height - outer_mid_space, location.Z)); outerRightLine.Layer = doorLineLayer; doc.AddEntity(outerLeftLine); doc.AddEntity(inLeftLine); doc.AddEntity(inRightLine); doc.AddEntity(outerRightLine); writeDoorRectangle(doc, location,text, height, width, outer_mid_space, outer_in_space); }
/// <summary> /// Processes a tlog to get the offsets - creates dxf of data /// </summary> /// <param name="fn">Filename</param> /// <returns>Offsets</returns> public static double[] getOffsets(string fn, int throttleThreshold = 0) { // based off tridge's work string logfile = fn; // old method float minx = 0; float maxx = 0; float miny = 0; float maxy = 0; float minz = 0; float maxz = 0; // this is for a dxf Polyline3dVertex vertex; List<Polyline3dVertex> vertexes = new List<Polyline3dVertex>(); // data storage Tuple<float, float, float> offset = new Tuple<float, float, float>(0, 0, 0); List<Tuple<float, float, float>> data = new List<Tuple<float, float, float>>(); Hashtable filter = new Hashtable(); // track data to use bool useData = false; log.Info("Start log: " + DateTime.Now); MAVLink mine = new MAVLink(); try { mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)); } catch (Exception ex) { log.Debug(ex.ToString()); CustomMessageBox.Show("Log Can not be opened. Are you still connected?"); return new double[] {0}; } mine.logreadmode = true; mine.MAV.packets.Initialize(); // clear // gather data while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { byte[] packetraw = mine.readPacket(); var packet = mine.DebugPacket(packetraw, false); // this is for packets we dont know about if (packet == null) continue; if (packet.GetType() == typeof(MAVLink.mavlink_vfr_hud_t)) { if (((MAVLink.mavlink_vfr_hud_t)packet).throttle >= throttleThreshold) { useData = true; } else { useData = false; } } if (packet.GetType() == typeof(MAVLink.mavlink_sensor_offsets_t)) { offset = new Tuple<float, float, float>( ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_x, ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_y, ((MAVLink.mavlink_sensor_offsets_t)packet).mag_ofs_z); } else if (packet.GetType() == typeof(MAVLink.mavlink_raw_imu_t) && useData) { int div = 20; // fox dxf vertex = new Polyline3dVertex(new Vector3f( ((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1, ((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2, ((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3) ); vertexes.Add(vertex); // for old method setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1, ref minx, ref maxx); setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2, ref miny, ref maxy); setMinorMax(((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3, ref minz, ref maxz); // for new lease sq string item = (int)(((MAVLink.mavlink_raw_imu_t)packet).xmag / div) + "," + (int)(((MAVLink.mavlink_raw_imu_t)packet).ymag / div) + "," + (int)(((MAVLink.mavlink_raw_imu_t)packet).zmag / div); if (filter.ContainsKey(item)) { filter[item] = (int)filter[item] + 1; if ((int)filter[item] > 3) continue; } else { filter[item] = 1; } data.Add(new Tuple<float, float, float>( ((MAVLink.mavlink_raw_imu_t)packet).xmag - offset.Item1, ((MAVLink.mavlink_raw_imu_t)packet).ymag - offset.Item2, ((MAVLink.mavlink_raw_imu_t)packet).zmag - offset.Item3)); } } log.Info("Log Processed " + DateTime.Now); Console.WriteLine("Extracted " + data.Count + " data points"); Console.WriteLine("Current offset: " + offset); mine.logreadmode = false; mine.logplaybackfile.Close(); mine.logplaybackfile = null; if (data.Count < 10) { CustomMessageBox.Show("Log does not contain enough data"); throw new Exception("Not Enough Data"); } data.Sort( delegate(Tuple<float, float, float> d1, Tuple<float, float, float> d2) { // get distance from 0,0,0 double ans1 = Math.Sqrt(d1.Item1 * d1.Item1 + d1.Item2 * d1.Item2+ d1.Item3 * d1.Item3); double ans2 = Math.Sqrt(d2.Item1 * d2.Item1 + d2.Item2 * d2.Item2+ d2.Item3 * d2.Item3); if (ans1 > ans2) return 1; if (ans1 < ans2) return -1; return 0; } ); data.RemoveRange(data.Count - (data.Count / 16), data.Count / 16); double[] x = LeastSq(data); System.Console.WriteLine("Old Method {0} {1} {2}", -(maxx + minx) / 2, -(maxy + miny) / 2, -(maxz + minz) / 2); log.Info("Least Sq Done " + DateTime.Now); // create a dxf for those who want to "see" the calibration DxfDocument dxf = new DxfDocument(); Polyline3d polyline = new Polyline3d(vertexes, true); polyline.Layer = new Layer("polyline3d"); polyline.Layer.Color.Index = 24; dxf.AddEntity(polyline); Point pnt = new Point(new Vector3f(-offset.Item1, -offset.Item2, -offset.Item3)); pnt.Layer = new Layer("old offset"); pnt.Layer.Color.Index = 22; dxf.AddEntity(pnt); pnt = new Point(new Vector3f(-(float)x[0], -(float)x[1], -(float)x[2])); pnt.Layer = new Layer("new offset"); pnt.Layer.Color.Index = 21; dxf.AddEntity(pnt); dxf.Save("magoffset.dxf", DxfVersion.AutoCad2000); log.Info("dxf Done " + DateTime.Now); Array.Resize<double>(ref x, 3); return x; }
//最外围矩形 public static void writeOuterDoorRectangle(DxfDocument doc, Location location,float height, float width) { //最外围矩形 Layer doorRectangleLayer = new Layer("DoorRectangleLayer"); Line outerBottomLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X + width, location.Y, location.Z)); outerBottomLine.Layer = doorRectangleLayer; Line outerLeftLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X, location.Y + height, location.Z)); outerLeftLine.Layer = doorRectangleLayer; Line outerTopLine = new Line(new Vector3f(location.X, location.Y + height, location.Z), new Vector3f(location.X + width, location.Y + height, location.Z)); outerTopLine.Layer = doorRectangleLayer; Line outerRightLine = new Line(new Vector3f(location.X + width, location.Y + height, location.Z), new Vector3f(location.X + width, location.Y, location.Z)); outerRightLine.Layer = doorRectangleLayer; doc.AddEntity(outerBottomLine); doc.AddEntity(outerLeftLine); doc.AddEntity(outerTopLine); doc.AddEntity(outerRightLine); }
/// <summary> /// 门把手绘制 /// </summary> /// <param name="dxf"></param> /// <param name="location"></param> public static void Draw(DxfDocument dxf, Location location) { float factor = 0.05f; float distance = 30; //底部小圆的圆心 Vector3f sCircle = new Vector3f(location.X + 10 * factor, location.Y, location.Z); //上部同心圆圆心 Vector3f bCircle = new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance*factor, location.Z); double alpha = Math.Asin(3 / distance); double beta = Math.Acos(0.8); Vector3f v1 = new Vector3f( location.X + 10 * factor - float.Parse((5 * factor * Math.Cos(alpha)).ToString()), location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()), location.Z); Vector3f v2 = new Vector3f( location.X + 10 * factor + float.Parse((5 * factor * Math.Cos(alpha)).ToString()), location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()), location.Z); Vector3f v4 = new Vector3f( location.X + 10 * factor -float.Parse((8*factor* Math.Cos(alpha)).ToString()), location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()), location.Z ); Vector3f v5 = new Vector3f( location.X + 10 * factor + float.Parse((8*factor*Math.Cos(alpha)).ToString()), location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()), location.Z ); Layer layer = new Layer("line"); Line line14 = new Line(v1, v4); line14.Layer = layer; line14.Layer.Color.Index = 6; dxf.AddEntity(line14); Line line25 = new Line(v2, v5); line25.Layer = new Layer("line"); line25.Layer = layer; dxf.AddEntity(line25); //arc Arc arc = new Arc( new Vector3f(location.X + 10 * factor, location.Y + 5 * factor, location.Z), 5 * factor, Convert.ToInt32(180 + alpha * 180 / Math.PI), Convert.ToInt32(360 - alpha * 180 / Math.PI)); arc.Layer = layer; dxf.AddEntity(arc); //arcup Arc arcup = new Arc( new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z), 8 * factor, Convert.ToInt32(-alpha * 180 / Math.PI), Convert.ToInt32(180 + alpha * 180 / Math.PI)); arcup.Layer = layer; dxf.AddEntity(arcup); //arcround Arc arcround = new Arc( new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z), 10 * factor, Convert.ToInt32(-(alpha +beta) * 180 / Math.PI), Convert.ToInt32(180 + (alpha +beta) * 180 / Math.PI)); arcround.Layer = layer; dxf.AddEntity(arcround); //circle Vector3f extrusion = new Vector3f(0, 0, 1); Vector3f centerWCS = new Vector3f(location.X+10*factor, location.Y+5*factor+distance*factor, location.Z); Vector3d centerOCS = MathHelper.Transform((Vector3d)centerWCS, (Vector3d)extrusion, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object); Circle circle = new Circle((Vector3f)centerOCS, 7*factor); circle.Layer = layer; circle.LineType = LineType.Continuous; circle.Normal = extrusion; dxf.AddEntity(circle); //上部同心圆圆心 Vector3f t1 = new Vector3f( location.X + 8 * factor, location.Y + 5 * factor + (distance - 7) * factor * 0.7f, location.Z); Vector3f t2 = new Vector3f( location.X + 8 * factor, location.Y + 5 * factor + (distance - 7) * factor * 0.5f, location.Z); Vector3f t3 = new Vector3f( location.X + 8 * factor, location.Y + 5 * factor + (distance - 7) * factor * 0.3f, location.Z); Vector3f t4 = new Vector3f( location.X + 8 * factor, location.Y + 5 * factor + (distance - 7) * factor * 0.1f, location.Z); //text TextStyle style = new TextStyle("True type font", "Arial.ttf"); Text text1 = new Text("A", t1, 0.2f, style); text1.Layer = layer; text1.Alignment = TextAlignment.TopLeft; dxf.AddEntity(text1); //text Text text2 = new Text("A", t2, 0.2f, style); text2.Layer = layer; text2.Alignment = TextAlignment.TopLeft; dxf.AddEntity(text2); //text Text text3 = new Text("O", t3, 0.2f, style); text3.Layer = layer; text3.Alignment = TextAlignment.TopLeft; dxf.AddEntity(text3); //text Text text4 = new Text("N", t4, 0.2f, style); text4.Layer = layer; text4.Alignment = TextAlignment.TopLeft; dxf.AddEntity(text4); }
//画表示门闩的小矩形 public static void writeRepresentDoorBarRectangle(DxfDocument doc, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space, float barHeight, float barWidth) { Layer representDoorBarRectangleLayer = new Layer("RepresentDoorBarRectangle"); Line bottomLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X + barWidth, location.Y, location.Z)); bottomLine.Layer = representDoorBarRectangleLayer; Line leftLine = new Line(new Vector3f(location.X, location.Y, location.Z), new Vector3f(location.X, location.Y + barHeight, location.Z)); leftLine.Layer = representDoorBarRectangleLayer; Line topLine = new Line(new Vector3f(location.X, location.Y + barHeight, location.Z), new Vector3f(location.X + barWidth, location.Y + barHeight, location.Z)); topLine.Layer = representDoorBarRectangleLayer; Line rightLine = new Line(new Vector3f(location.X + barWidth, location.Y + barHeight, location.Z), new Vector3f(location.X + barWidth, location.Y, location.Z)); rightLine.Layer = representDoorBarRectangleLayer; //内部折线 Line upLine = new Line(new Vector3f(location.X + barWidth / 2-(outer_in_space-outer_mid_space)/2, location.Y + barHeight, location.Z), new Vector3f(location.X + barWidth / 2-(outer_in_space-outer_mid_space)/2, location.Y + barHeight / 2, location.Z)); upLine.Layer = representDoorBarRectangleLayer; Line midLine = new Line(new Vector3f(location.X + barWidth / 2 - (outer_in_space - outer_mid_space) / 2, location.Y + barHeight / 2, location.Z), new Vector3f(location.X + barWidth / 2 + (outer_in_space - outer_mid_space) / 2,location.Y+barHeight/2,location.Z)); midLine.Layer = representDoorBarRectangleLayer; Line downLine = new Line(new Vector3f(location.X + barWidth / 2 + (outer_in_space - outer_mid_space) / 2, location.Y + barHeight / 2, location.Z), new Vector3f(location.X+barWidth/2+(outer_in_space-outer_mid_space)/2, location.Y, location.Z)); downLine.Layer = representDoorBarRectangleLayer; doc.AddEntity(bottomLine); doc.AddEntity(leftLine); doc.AddEntity(topLine); doc.AddEntity(rightLine); doc.AddEntity(upLine); doc.AddEntity(midLine); doc.AddEntity(downLine); }