public void DrawContourMap() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; // Surface type Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } // Pick interval Topography topo = Topography.Instance; PromptDoubleOptions dblOpts = new PromptDoubleOptions("\nKontur aralığı: "); dblOpts.AllowNegative = false; dblOpts.AllowZero = false; dblOpts.DefaultValue = ContourInterval; dblOpts.UseDefaultValue = true; PromptDoubleResult dblRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDouble(dblOpts); if (dblRes.Status == PromptStatus.OK) { ContourInterval = dblRes.Value; using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { IEnumerable <Polyline> contours = topo.ContourMap(surface, ContourInterval); foreach (Polyline pline in contours) { btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } tr.Commit(); } } }
public void Drape() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } // Pick polyline PromptEntityOptions entityOpts = new PromptEntityOptions("\nEğri: "); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { Curve curve = tr.GetObject(entityRes.ObjectId, OpenMode.ForRead) as Curve; Topography topo = Topography.Instance; Point3dCollection points = topo.DrapeCurve(curve, surface); Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, curve.Closed, points); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); tr.Commit(); } } }
public void CreateSurface() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (ShowSettings()) { try { IEnumerable <ObjectId> items = SelectEntitites(); Point3dCollection points = ReadPoints(items, MaxPointSpacing); if (points.Count > 0) { Topography topo = Topography.Instance; topo.SurfaceFromPoints(points, surface); doc.Editor.WriteMessage(topo.OriginalTIN.Triangles.Count.ToString() + " adet üçgen oluşturuldu."); } if (EraseEntities) { AcadUtility.AcadEntity.EraseEntities(db, items); } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void DrawSurface() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography topo = Topography.Instance; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } TriangleNet.Mesh mesh = (surface == Topography.SurfaceType.Original ? topo.OriginalTIN : topo.ProposedTIN); // Object type PromptKeywordOptions opts = new PromptKeywordOptions("\nÇizim nesneleri [Geçici/3dFace/Point/polyfaceMesh] <Geçici>: ", "Temporary 3dFace Point polyfaceMesh"); opts.Keywords.Default = "Temporary"; opts.AllowNone = true; PromptResult res = doc.Editor.GetKeywords(opts); string outputType = res.StringResult; if (res.Status == PromptStatus.None) { outputType = "Temporary"; } else if (res.Status != PromptStatus.OK) { return; } // Color option opts = new PromptKeywordOptions("\nRenkli çizim [E/H] <E>: ", "Yes No"); opts.Keywords.Default = "Yes"; opts.AllowNone = true; res = doc.Editor.GetKeywords(opts); bool useColor = true; if (res.Status == PromptStatus.None) { useColor = true; } else if (res.Status != PromptStatus.OK) { return; } else { useColor = (string.Compare(res.StringResult, "Yes", StringComparison.OrdinalIgnoreCase) == 0); } double zmin = double.MaxValue; double zmax = double.MinValue; foreach (TriangleNet.Data.Vertex v in mesh.Vertices) { zmin = Math.Min(zmin, v.Attributes[0]); zmax = Math.Max(zmax, v.Attributes[0]); } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { try { if (string.Compare(outputType, "Temporary", StringComparison.OrdinalIgnoreCase) == 0) { EraseTemporaryGraphics(); foreach (TriangleNet.Data.Triangle tri in mesh.Triangles) { TriangleNet.Data.Vertex v1 = tri.GetVertex(0); TriangleNet.Data.Vertex v2 = tri.GetVertex(1); TriangleNet.Data.Vertex v3 = tri.GetVertex(2); Face face = new Face(new Point3d(v1.X, v1.Y, v1.Attributes[0]), new Point3d(v2.X, v2.Y, v2.Attributes[0]), new Point3d(v3.X, v3.Y, v3.Attributes[0]), true, true, true, true); if (useColor) { face.Color = ColorFromZ((v1.Attributes[0] + v2.Attributes[0] + v3.Attributes[0]) / 3, zmin, zmax); } temporaryGraphics.Add(face); } DrawTemporaryGraphics(); } else if (string.Compare(outputType, "3dFace", StringComparison.OrdinalIgnoreCase) == 0) { foreach (TriangleNet.Data.Triangle tri in mesh.Triangles) { TriangleNet.Data.Vertex v1 = tri.GetVertex(0); TriangleNet.Data.Vertex v2 = tri.GetVertex(1); TriangleNet.Data.Vertex v3 = tri.GetVertex(2); Face face = new Face(new Point3d(v1.X, v1.Y, v1.Attributes[0]), new Point3d(v2.X, v2.Y, v2.Attributes[0]), new Point3d(v3.X, v3.Y, v3.Attributes[0]), true, true, true, true); if (useColor) { face.Color = ColorFromZ((v1.Attributes[0] + v2.Attributes[0] + v3.Attributes[0]) / 3, zmin, zmax); } btr.AppendEntity(face); tr.AddNewlyCreatedDBObject(face, true); } } else if (string.Compare(outputType, "Point", StringComparison.OrdinalIgnoreCase) == 0) { foreach (TriangleNet.Data.Vertex v in mesh.Vertices) { DBPoint point = new DBPoint(new Point3d(v.X, v.Y, v.Attributes[0])); if (useColor) { point.Color = ColorFromZ(v.Attributes[0], zmin, zmax); } btr.AppendEntity(point); tr.AddNewlyCreatedDBObject(point, true); } } else if (string.Compare(outputType, "polyfaceMesh", StringComparison.OrdinalIgnoreCase) == 0) { PolyFaceMesh pfm = new PolyFaceMesh(); btr.AppendEntity(pfm); tr.AddNewlyCreatedDBObject(pfm, true); // Vertices SortedDictionary <int, Point3d> vertices = new SortedDictionary <int, Point3d>(); foreach (TriangleNet.Data.Vertex v in mesh.Vertices) { vertices.Add(v.ID, new Point3d(v.X, v.Y, v.Attributes[0])); } foreach (KeyValuePair <int, Point3d> v in vertices) { PolyFaceMeshVertex point = new PolyFaceMeshVertex(v.Value); pfm.AppendVertex(point); tr.AddNewlyCreatedDBObject(point, true); } // Faces foreach (TriangleNet.Data.Triangle tri in mesh.Triangles) { FaceRecord face = new FaceRecord((short)(tri.P0 + 1), (short)(tri.P1 + 1), (short)(tri.P2 + 1), 0); if (useColor) { face.Color = ColorFromZ((tri.GetVertex(0).Attributes[0] + tri.GetVertex(1).Attributes[0] + tri.GetVertex(2).Attributes[0]) / 3, zmin, zmax); } pfm.AppendFaceRecord(face); tr.AddNewlyCreatedDBObject(face, true); } } } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } }
public void TrenchExcavation() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } Topography topo = Topography.Instance; TriangleNet.Mesh mesh = (surface == Topography.SurfaceType.Original ? topo.OriginalTIN : topo.ProposedTIN); // Pick polyline bool flag = true; ObjectId centerlineId = ObjectId.Null; while (flag) { PromptEntityOptions entityOpts = new PromptEntityOptions("\nKazı tabanı [Seçenekler]:", "Settings"); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.Keyword && entityRes.StringResult == "Settings") { ShowSettings(); continue; } else if (entityRes.Status == PromptStatus.OK) { centerlineId = entityRes.ObjectId; break; } else { return; } } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { Curve centerline = tr.GetObject(centerlineId, OpenMode.ForRead) as Curve; // Excavate TrenchExcavation ex = new TrenchExcavation(mesh, centerline, Width, ExcavationStepSize); ExcavationSection slope = new ExcavationSection(); slope.AddSlope(ExcavationH, ExcavationV); ex.AddSection(0, slope); ex.Excavate(); // Draw excavation boundries Point3dCollection bottombounds = new Point3dCollection(); Point3dCollection topbounds = new Point3dCollection(); bool closed = true; bool alt = false; foreach (ExcavationSection section in ex.OutputSections) { if (section.Elements[section.Elements.Count - 1].HasTopPoint) { bottombounds.Add(section.Elements[0].BottomPoint); topbounds.Add(section.Elements[section.Elements.Count - 1].TopPoint); Point3d pt1 = section.Elements[0].BottomPoint; Point3d pt2 = section.Elements[section.Elements.Count - 1].TopPoint; if (alt) { pt1 = pt1 + (pt2 - pt1) / 2; } Line line = AcadUtility.AcadEntity.CreateLine(db, pt1, pt2); line.ColorIndex = 11; btr.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); } else { if (bottombounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, bottombounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } if (topbounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, topbounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } closed = false; topbounds = new Point3dCollection(); } alt = !alt; } if (bottombounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, bottombounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } if (topbounds.Count > 1) { Polyline3d pline = AcadUtility.AcadEntity.CreatePolyLine3d(db, closed, topbounds); btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } tr.Commit(); } }
public void ProfileOnCurve() { if (!CheckLicense.Check()) { return; } Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Topography.SurfaceType surface = Topography.PickSurface(); if (surface == Topography.SurfaceType.None) { return; } if (!Topography.EnsureSurfaceNotEmpty(surface)) { return; } // Pick alignment bool flag = true; ObjectId curveId = ObjectId.Null; while (flag) { PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen [Seçenekler]: ", "Settings"); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.Keyword) { ShowSettings(); } else if (entityRes.Status == PromptStatus.OK) { curveId = entityRes.ObjectId; break; } else if (entityRes.Status == PromptStatus.Cancel) { return; } } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs; ObjectId textStyleId = ObjectId.Null; using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead)) { if (tt.Has(TextStyleName)) { textStyleId = tt[TextStyleName]; } } // Project curve onto surface Topography topo = Topography.Instance; Curve curve = tr.GetObject(curveId, OpenMode.ForRead) as Curve; Point2dCollection points = topo.ProfileOnCurve(curve, surface); // Base point for profile drawing PromptPointResult pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nProfil başlangıcı: "); if (pointRes.Status != PromptStatus.OK) { return; } Point3d basePt = pointRes.Value; if (points.Count > 0) { // Limits Extents2d ex = AcadUtility.AcadGeometry.Limits(points); // Base level for profile drawing PromptDoubleOptions levelOpts = new PromptDoubleOptions("\nProfil baz kotu: "); levelOpts.DefaultValue = Math.Floor(ex.MinPoint.Y / ProfileGridV) * ProfileGridV; levelOpts.UseDefaultValue = true; PromptDoubleResult levelRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetDouble(levelOpts); if (pointRes.Status != PromptStatus.OK) { return; } double startLevel = levelRes.Value; double endLevel = Math.Ceiling(ex.MaxPoint.Y / ProfileGridV + 1) * ProfileGridV; // Base chainage for profile drawing double startCh = 0; flag = true; while (flag) { PromptStringOptions chOpts = new PromptStringOptions("\nProfil baz KM: "); chOpts.DefaultValue = AcadUtility.AcadText.ChainageToString(0, Precision); chOpts.UseDefaultValue = true; PromptResult chRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetString(chOpts); if (chRes.Status != PromptStatus.OK) { return; } if (AcadUtility.AcadText.TryChainageFromString(chRes.StringResult, out startCh)) { break; } } double endCh = Math.Ceiling((startCh + ex.MaxPoint.X) / ProfileGridH) * ProfileGridH; // Draw grid IEnumerable <Entity> entities = DrawProfileFrame(db, basePt, startCh, startLevel, endCh, endLevel, ProfileGridH, ProfileGridV, ProfileVScale, TextHeight, Precision, textStyleId); foreach (Entity ent in entities) { ent.TransformBy(ucs2wcs); btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } // Draw profile ObjectId profileLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, "Profil_Eksen", Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 5)); Point2dCollection trPoints = new Point2dCollection(points.Count); foreach (Point2d pt in points) { trPoints.Add(new Point2d(basePt.X + pt.X, basePt.Y + (pt.Y - startLevel) * ProfileVScale)); } Polyline pline = AcadUtility.AcadEntity.CreatePolyLine(db, false, trPoints); pline.TransformBy(ucs2wcs); pline.LayerId = profileLayerId; btr.AppendEntity(pline); tr.AddNewlyCreatedDBObject(pline, true); } tr.Commit(); } }