public void DrawDeck() { if (!CheckLicense.Check()) { return; } var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; Matrix3d ucs2wcs = AcadGraphics.UcsToWcs; Matrix3d wcs2ucs = AcadGraphics.WcsToUcs; Alignment = Bridge.PickAlignment(); if (Alignment == Bridge.AlignmentType.None) { return; } PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen: "); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = ed.GetEntity(entityOpts); if (entityRes.Status != PromptStatus.OK) { return; } CenterlineId = entityRes.ObjectId; var resp1 = ed.GetPoint("\nBaşlangıç noktası: "); if (resp1.Status != PromptStatus.OK) { return; } StartPoint = resp1.Value.TransformBy(ucs2wcs); var resp2 = ed.GetPoint("\nBitiş noktası: "); if (resp2.Status != PromptStatus.OK) { return; } EndPoint = resp2.Value.TransformBy(ucs2wcs); var opts = new PromptDistanceOptions("\nAsktan taşma mesafesi: "); opts.AllowNegative = false; opts.AllowZero = false; opts.DefaultValue = OverhangDistance; opts.UseDefaultValue = true; opts.BasePoint = resp1.Value; var res = ed.GetDistance(opts); if (res.Status != PromptStatus.OK) { return; } OverhangDistance = res.Value; if (Alignment == Bridge.AlignmentType.Plan) { var opts1 = new PromptDistanceOptions("\nTabliye genişliği: "); opts1.AllowNegative = false; opts1.AllowZero = false; opts1.DefaultValue = DeckWidth; opts1.UseDefaultValue = true; opts1.BasePoint = resp1.Value; var reso1 = ed.GetDistance(opts1); if (reso1.Status != PromptStatus.OK) { return; } DeckWidth = reso1.Value; } else { var opts1 = new PromptDistanceOptions("\nAsfalt kalınlığı: "); opts1.AllowNegative = false; opts1.AllowZero = false; opts1.DefaultValue = AsphaltThickness; opts1.UseDefaultValue = true; var reso1 = ed.GetDistance(opts1); if (reso1.Status != PromptStatus.OK) { return; } AsphaltThickness = reso1.Value; var opts2 = new PromptDistanceOptions("\nTabliye kalınlığı: "); opts2.AllowNegative = false; opts2.AllowZero = false; opts2.DefaultValue = DeckThickness; opts2.UseDefaultValue = true; var reso2 = ed.GetDistance(opts2); if (reso2.Status != PromptStatus.OK) { return; } DeckThickness = reso2.Value; var opts3 = new PromptDistanceOptions("\nKaldırım kalınlığı: "); opts3.AllowNegative = false; opts3.AllowZero = false; opts3.DefaultValue = SidewalkThickness; opts3.UseDefaultValue = true; var reso3 = ed.GetDistance(opts3); if (reso3.Status != PromptStatus.OK) { return; } SidewalkThickness = reso3.Value; } using (Transaction tr = db.TransactionManager.StartTransaction()) using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)) { try { ObjectId lineLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, DeckLayerName, Color.FromColorIndex(ColorMethod.ByAci, 4)); ObjectId hatchLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, HatchLayerName, Color.FromColorIndex(ColorMethod.ByAci, 31)); ObjectId sidewalkLayerId = AcadUtility.AcadEntity.GetOrCreateLayer(db, SidewalkLayerName, Color.FromColorIndex(ColorMethod.ByAci, 21)); // Adjust start and end point to account for overhang Curve centerline = tr.GetObject(CenterlineId, OpenMode.ForRead) as Curve; if (Alignment == Bridge.AlignmentType.Plan) { StartPoint = centerline.GetClosestPointTo(StartPoint, false); double startDistance = centerline.GetDistAtPoint(StartPoint) - OverhangDistance; StartPoint = centerline.GetPointAtDist(startDistance); EndPoint = centerline.GetClosestPointTo(EndPoint, false); double endDistance = centerline.GetDistAtPoint(EndPoint) + OverhangDistance; EndPoint = centerline.GetPointAtDist(endDistance); using (Plane horizontal = new Plane(Point3d.Origin, Vector3d.ZAxis)) { Curve planCurve = centerline.GetOrthoProjectedCurve(horizontal); planCurve = planCurve.GetTrimmedCurve(StartPoint, EndPoint, true); Vector3d dir = planCurve.GetFirstDerivative(planCurve.StartParam).CrossProduct(Vector3d.ZAxis); dir /= dir.Length; var rightCurve = planCurve.GetOffsetCurves(planCurve.StartPoint + dir * DeckWidth / 2)[0] as Curve; var leftCurve = planCurve.GetOffsetCurves(planCurve.StartPoint - dir * DeckWidth / 2)[0] as Curve; // Join curves and close ends with lines var finalCurve = AcadEntity.CreatePolyLine(db, true, rightCurve, AcadEntity.CreateLine(db, rightCurve.StartPoint, leftCurve.StartPoint), leftCurve, AcadEntity.CreateLine(db, rightCurve.EndPoint, leftCurve.EndPoint)); var finalCurveId = btr.AppendEntity(finalCurve); tr.AddNewlyCreatedDBObject(finalCurve, true); finalCurve.LayerId = lineLayerId; // Hatch inside var hatch = new Hatch(); btr.AppendEntity(hatch); tr.AddNewlyCreatedDBObject(hatch, true); hatch.LayerId = hatchLayerId; hatch.Associative = true; hatch.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection() { finalCurveId }); hatch.PatternScale = HatchScale; hatch.SetHatchPattern(HatchPatternType.PreDefined, HatchPattern); hatch.EvaluateHatch(true); } } else { Vector3d upDir = db.Ucsydir; var topline = centerline.GetTransformedCopy(Matrix3d.Displacement(upDir * -AsphaltThickness)) as Curve; var bottomline = topline.GetTransformedCopy(Matrix3d.Displacement(upDir * -DeckThickness)) as Curve; var sidewalkline = topline.GetTransformedCopy(Matrix3d.Displacement(upDir * SidewalkThickness)) as Curve; using (Plane horizontal = new Plane(Point3d.Origin, upDir)) { Curve planCurve = centerline.GetOrthoProjectedCurve(horizontal); Point3d startPointOnPlan = planCurve.GetClosestPointTo(StartPoint, true); double startDistance = planCurve.GetDistAtPoint(startPointOnPlan) - OverhangDistance; startPointOnPlan = planCurve.GetPointAtDist(startDistance); StartPoint = centerline.GetClosestPointTo(startPointOnPlan, upDir, true); Point3d endPointOnPlan = planCurve.GetClosestPointTo(EndPoint, true); double endDistance = planCurve.GetDistAtPoint(endPointOnPlan) + OverhangDistance; endPointOnPlan = planCurve.GetPointAtDist(endDistance); EndPoint = centerline.GetClosestPointTo(endPointOnPlan, upDir, true); } topline = topline.GetTrimmedCurve(topline.GetClosestPointTo(StartPoint, upDir, true), topline.GetClosestPointTo(EndPoint, upDir, true), true); bottomline = bottomline.GetTrimmedCurve(bottomline.GetClosestPointTo(StartPoint, upDir, true), bottomline.GetClosestPointTo(EndPoint, upDir, true), true); sidewalkline = sidewalkline.GetTrimmedCurve(sidewalkline.GetClosestPointTo(StartPoint, upDir, true), sidewalkline.GetClosestPointTo(EndPoint, upDir, true), true); // Sidewalk var finalSWCurve = AcadEntity.CreatePolyLine(db, false, AcadEntity.CreateLine(db, topline.StartPoint, sidewalkline.StartPoint), sidewalkline, AcadEntity.CreateLine(db, topline.EndPoint, sidewalkline.EndPoint)); btr.AppendEntity(finalSWCurve); tr.AddNewlyCreatedDBObject(finalSWCurve, true); finalSWCurve.LayerId = sidewalkLayerId; // Deck polyline var finalCurve = AcadEntity.CreatePolyLine(db, true, topline, AcadEntity.CreateLine(db, topline.StartPoint, bottomline.StartPoint), bottomline, AcadEntity.CreateLine(db, topline.EndPoint, bottomline.EndPoint)); ObjectId finalCurveId = btr.AppendEntity(finalCurve); tr.AddNewlyCreatedDBObject(finalCurve, true); finalCurve.LayerId = lineLayerId; // Hatch inside var hatch = new Hatch(); btr.AppendEntity(hatch); tr.AddNewlyCreatedDBObject(hatch, true); hatch.LayerId = hatchLayerId; hatch.Associative = true; hatch.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection() { finalCurveId }); hatch.PatternScale = HatchScale; hatch.SetHatchPattern(HatchPatternType.PreDefined, HatchPattern); hatch.EvaluateHatch(true); } } catch (System.Exception e) { MessageBox.Show(e.ToString(), "XCOM", MessageBoxButtons.OK, MessageBoxIcon.Error); } tr.Commit(); } }
private bool GetAlignmentParameters() { var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; Matrix3d ucs2wcs = AcadGraphics.UcsToWcs; Matrix3d wcs2ucs = AcadGraphics.WcsToUcs; // Alignment type Alignment = Bridge.PickAlignment(); if (Alignment == Bridge.AlignmentType.None) { return(false); } // Alignment line PromptEntityOptions entityOpts = new PromptEntityOptions("\nEksen: "); entityOpts.SetRejectMessage("\nSelect a curve."); entityOpts.AddAllowedClass(typeof(Curve), false); PromptEntityResult entityRes = ed.GetEntity(entityOpts); if (entityRes.Status == PromptStatus.OK) { CenterlineId = entityRes.ObjectId; } else { return(false); } // Start point PromptPointResult ptRes = ed.GetPoint("\nBaşlangıç noktası: "); if (ptRes.Status == PromptStatus.OK) { StartPoint = ptRes.Value.TransformBy(ucs2wcs); } else { return(false); } // Start CH AcadEditor.PromptChainageOptions chOpts = new AcadEditor.PromptChainageOptions("\nBaşlangıç kilometresi: "); chOpts.DefaultValue = AcadText.ChainageToString(StartCH, ChPrecision); chOpts.UseDefaultValue = true; AcadEditor.PromptChainageResult chRes = ed.GetChainage(chOpts); if (chRes.Status == PromptStatus.OK) { StartCH = chRes.DoubleResult; } else if (chRes.Status == PromptStatus.None) { // Use default } else if (chRes.Status != PromptStatus.OK) { return(false); } return(true); }