private Point3d GetTopStrokeEndPoint(Point3d insertionPoint, Point3d endPoint, List <Point3d> middlePoints, double scale) { if (MiddlePoints.Any()) { return(insertionPoint + ((insertionPoint - middlePoints.First()).GetNormal() * StrokeLength * scale)); } return(insertionPoint + ((insertionPoint - endPoint).GetNormal() * StrokeLength * scale)); }
private void CreateEntities(Point3d insertionPoint, List <Point3d> middlePoints, Point3d endPoint, double scale) { var strokesWidth = StrokeWidth * scale; // top and bottom strokes var topStrokeEndPoint = GetTopStrokeEndPoint(insertionPoint, endPoint, middlePoints, scale); var bottomStrokeEndPoint = GetBottomStrokeEndPoint(insertionPoint, endPoint, middlePoints, scale); _topStroke = new Polyline(2); _topStroke.AddVertexAt(0, topStrokeEndPoint.ConvertPoint3dToPoint2d(), 0.0, strokesWidth, strokesWidth); _topStroke.AddVertexAt(1, insertionPoint.ConvertPoint3dToPoint2d(), 0.0, strokesWidth, strokesWidth); _bottomStroke = new Polyline(2); _bottomStroke.AddVertexAt(0, endPoint.ConvertPoint3dToPoint2d(), 0.0, strokesWidth, strokesWidth); _bottomStroke.AddVertexAt(1, bottomStrokeEndPoint.ConvertPoint3dToPoint2d(), 0.0, strokesWidth, strokesWidth); var topStrokeNormalVector = (topStrokeEndPoint - insertionPoint).GetNormal(); var bottomStrokeNormalVector = (bottomStrokeEndPoint - endPoint).GetNormal(); // shelf lines var topShelfStartPoint = insertionPoint + (topStrokeNormalVector * GetShelfOffset() * scale); var topShelfEndPoint = topShelfStartPoint + (topStrokeNormalVector.GetPerpendicularVector() * ShelfLength * scale); TopShelfEndPoint = topShelfEndPoint.TransformBy(BlockTransform); _topShelfLine = new Line { StartPoint = topShelfStartPoint, EndPoint = topShelfEndPoint }; var bottomShelfStartPoint = endPoint + (bottomStrokeNormalVector * GetShelfOffset() * scale); var bottomShelfEndPoint = bottomShelfStartPoint + (bottomStrokeNormalVector.GetPerpendicularVector().Negate() * ShelfLength * scale); BottomShelfEndPoint = bottomShelfEndPoint.TransformBy(BlockTransform); _bottomShelfLine = new Line { StartPoint = bottomShelfStartPoint, EndPoint = bottomShelfEndPoint }; // shelf arrows var topShelfArrowStartPoint = topShelfStartPoint + (topStrokeNormalVector.GetPerpendicularVector() * ShelfArrowLength * scale); _topShelfArrow = new Polyline(2); _topShelfArrow.AddVertexAt(0, topShelfArrowStartPoint.ConvertPoint3dToPoint2d(), 0.0, ShelfArrowWidth * scale, 0.0); _topShelfArrow.AddVertexAt(1, topShelfStartPoint.ConvertPoint3dToPoint2d(), 0.0, 0.0, 0.0); var bottomShelfArrowStartPoint = bottomShelfStartPoint + (bottomStrokeNormalVector.GetPerpendicularVector().Negate() * ShelfArrowLength * scale); _bottomShelfArrow = new Polyline(2); _bottomShelfArrow.AddVertexAt(0, bottomShelfArrowStartPoint.ConvertPoint3dToPoint2d(), 0.0, ShelfArrowWidth * scale, 0.0); _bottomShelfArrow.AddVertexAt(1, bottomShelfStartPoint.ConvertPoint3dToPoint2d(), 0.0, 0.0, 0.0); // text var textContentsForTopText = GetTextContents(true); var textContentsForBottomText = GetTextContents(false); if (!string.IsNullOrEmpty(textContentsForTopText) && !string.IsNullOrEmpty(textContentsForBottomText)) { var textStyleId = AcadUtils.GetTextStyleIdByName(TextStyle); var textHeight = MainTextHeight * scale; _topMText = new MText { TextStyleId = textStyleId, Contents = textContentsForTopText, TextHeight = textHeight, Attachment = AttachmentPoint.MiddleCenter }; _bottomMText = new MText { TextStyleId = textStyleId, Contents = textContentsForBottomText, TextHeight = textHeight, Attachment = AttachmentPoint.MiddleCenter }; // TextActualHeight = _topMText.ActualHeight; // TextActualWidth = _topMText.ActualWidth; var check = 1 / Math.Sqrt(2); // top var alongShelfTextOffset = _topMText.ActualWidth / 2; var acrossShelfTextOffset = _topMText.ActualHeight / 2; if (double.IsNaN(AlongTopShelfTextOffset) && double.IsNaN(AcrossTopShelfTextOffset)) { if ((topStrokeNormalVector.X > check || topStrokeNormalVector.X < -check) && (topStrokeNormalVector.Y < check || topStrokeNormalVector.Y > -check)) { alongShelfTextOffset = _topMText.ActualHeight / 2; acrossShelfTextOffset = _topMText.ActualWidth / 2; } var tempPoint = topShelfEndPoint + ((topShelfStartPoint - topShelfEndPoint).GetNormal() * alongShelfTextOffset); var topTextCenterPoint = tempPoint + (topStrokeNormalVector * ((2 * scale) + acrossShelfTextOffset)); _topMText.Location = topTextCenterPoint; } else { var tempPoint = topShelfEndPoint + ((topShelfStartPoint - topShelfEndPoint).GetNormal() * (AlongTopShelfTextOffset + (_topMText.ActualWidth / 2))); var topTextCenterPoint = tempPoint + (topStrokeNormalVector * ((2 * scale) + (AcrossTopShelfTextOffset + (_topMText.ActualHeight / 2)))); _topMText.Location = topTextCenterPoint; } TopDesignationPoint = _topMText.GeometricExtents.MinPoint.TransformBy(BlockTransform); // bottom alongShelfTextOffset = _bottomMText.ActualWidth / 2; acrossShelfTextOffset = _bottomMText.ActualHeight / 2; if (double.IsNaN(AlongBottomShelfTextOffset) && double.IsNaN(AcrossBottomShelfTextOffset)) { if ((bottomStrokeNormalVector.X > check || bottomStrokeNormalVector.X < -check) && (bottomStrokeNormalVector.Y < check || bottomStrokeNormalVector.Y > -check)) { alongShelfTextOffset = _topMText.ActualHeight / 2; acrossShelfTextOffset = _topMText.ActualWidth / 2; } var tempPoint = bottomShelfEndPoint + ((bottomShelfStartPoint - bottomShelfEndPoint).GetNormal() * alongShelfTextOffset); var bottomTextCenterPoint = tempPoint + (bottomStrokeNormalVector * ((2 * scale) + acrossShelfTextOffset)); _bottomMText.Location = bottomTextCenterPoint; } else { var tempPoint = bottomShelfEndPoint + ((bottomShelfStartPoint - bottomShelfEndPoint).GetNormal() * (AlongBottomShelfTextOffset + (_bottomMText.ActualWidth / 2))); var bottomTextCenterPoint = tempPoint + (bottomStrokeNormalVector * ((2 * scale) + (AcrossBottomShelfTextOffset + (_bottomMText.ActualHeight / 2)))); _bottomMText.Location = bottomTextCenterPoint; } BottomDesignationPoint = _bottomMText.GeometricExtents.MinPoint.TransformBy(BlockTransform); } _middleStrokes.Clear(); // middle strokes if (MiddlePoints.Any()) { var middleStrokeLength = MiddleStrokeLength * scale; var points = new List <Point3d> { insertionPoint }; points.AddRange(middlePoints); points.Add(endPoint); for (var i = 1; i < points.Count - 1; i++) { var previousPoint = points[i - 1]; var currentPoint = points[i]; var nextPoint = points[i + 1]; var middleStrokePolyline = new Polyline(3); middleStrokePolyline.AddVertexAt( 0, (currentPoint + ((previousPoint - currentPoint).GetNormal() * middleStrokeLength)).ConvertPoint3dToPoint2d(), 0, strokesWidth, strokesWidth); middleStrokePolyline.AddVertexAt(1, currentPoint.ConvertPoint3dToPoint2d(), 0, strokesWidth, strokesWidth); middleStrokePolyline.AddVertexAt( 2, (currentPoint + ((nextPoint - currentPoint).GetNormal() * middleStrokeLength)).ConvertPoint3dToPoint2d(), 0, strokesWidth, strokesWidth); _middleStrokes.Add(middleStrokePolyline); } } }