private static LevelBlockDetails GenerateOrUpdateBlock(Editor ed, Database db, GenerateArgs args) { if (IsNewBlock(ed)) { var endPoint = ed.PromptForPosition(Resources.Command_Prompt_SelectEndPoint); if (!endPoint.HasValue) { return(LevelBlockDetails.CreateEmpty()); } var levelArgs = CreateNewBlockLevelBlockArgs(args, endPoint.Value); return(LevelBlockHelper.NewLevelBlockAtPoint(db, levelArgs)); } var trans = db.TransactionManager.TopTransaction; var existing = LevelBlockHelper.GetPromptedBlockDetails(Resources.Command_Prompt_SelectExistingLevelBlock, ed, trans); if (!existing.IsValid) { return(LevelBlockDetails.CreateEmpty()); } if (args.HasLevel) { return(LevelBlockHelper.UpdateExistingLevelBlock(existing.BlockReference, args.BlockLevel)); } var endLevel = CalculateLevel(args.StartPoint, existing.Point3d, args.StartLevel, args.Gradient); return(LevelBlockHelper.UpdateExistingLevelBlock(existing.BlockReference, endLevel)); }
private static void AddBackOfFootwayLevel(double level) { var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var db = doc.Database; using var trans = db.TransactionManager.StartTransaction(); if (!LevelBlockHelper.HasLevelBlock(db)) { throw new ArgumentException(Resources.Exception_NoLevelBlock); } var roadString = SelectRoadString(db, ed); if (roadString == null) { HousingExtensionApplication.Current.Logger.Entry(Resources.Message_No_Road_String_Selected); return; } using (var plane = new Plane(Point3d.Origin, Vector3d.ZAxis)) { var point = ed.PromptForPosition(Resources.Command_Prompt_SelectFootwayPoint); while (point.HasValue) { var roadPoint = roadString.GetClosestPointTo(point.Value, plane.Normal, false); var roadLevel = Math.Round(roadPoint.Z, 3); var footwayLevel = roadLevel + level; LevelBlockHelper.NewLevelBlockAtPoint(db, new LevelBlockArgs(point.Value, footwayLevel)); point = ed.PromptForPosition(Resources.Command_Prompt_SelectFootwayPoint); } } trans.Commit(); }
public static void CalculateLevelBetweenLevels() { HousingExtensionApplication.Current.Logger.LogCommand(typeof(LevelBlockCommands), nameof(CalculateLevelBetweenLevels)); var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var db = doc.Database; using var trans = db.TransactionManager.StartTransaction(); if (!LevelBlockHelper.HasLevelBlock(db)) { throw new ArgumentException(Resources.Exception_NoLevelBlock); } var details = CommandHelper.GetStartEndDetails(ed, trans); if (!details.IsValid) { return; } var s = new Point3d(details.Start.Point2d.X, details.Start.Point2d.Y, 0); var e = new Point3d(details.End.Point2d.X, details.End.Point2d.Y, 0); Point3d?midPoint; using var line = new Line(s, e) { Color = Color.FromRgb(0, 255, 0) }; { var acBlkTbl = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); var acBlkTblRec = (BlockTableRecord)trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite); acBlkTblRec.AppendEntity(line); trans.AddNewlyCreatedDBObject(line, true); db.TransactionManager.QueueForGraphicsFlush(); // TODO: Review graphics flush in core console. midPoint = ed.PromptForPosition(Resources.Command_Prompt_SelectMidPoint); while (midPoint.HasValue) { var m = new Point3d(midPoint.Value.X, midPoint.Value.Y, 0); if (line.GetGeCurve().IsOn(m)) { break; } midPoint = ed.PromptForPosition(Resources.Command_Prompt_SelectMidPoint); } line.Erase(); db.TransactionManager.QueueForGraphicsFlush(); // TODO: Review graphics flush in core console. } if (!midPoint.HasValue) { return; //Assume user cancelled } var gradient = 1 / ((details.End.Level - details.Start.Level) / line.Length); var midLevel = CalculateLevel(details.Start.Point3d, midPoint.Value, details.Start.Level, gradient); var args = new LevelBlockArgs(midPoint.Value, midLevel, details.Start.Rotation, details.Start.Rotate); LevelBlockHelper.NewLevelBlockAtPoint(db, args); trans.Commit(); }