Пример #1
0
        private static Point2dCollection GetPointsForMainPolyline(Point3d insertionPoint, List <Point3d> middlePoints, Point3d endPoint)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var points = new Point2dCollection();

            points.Add(insertionPoint.ConvertPoint3dToPoint2d());
            middlePoints.ForEach(p => points.Add(p.ConvertPoint3dToPoint2d()));
            points.Add(endPoint.ConvertPoint3dToPoint2d());

            return(points);
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Получение точек для построения базовой полилинии
        /// </summary>
        private Point2dCollection PointsToCreatePolyline(
            double scale, Point3d insertionPoint, Point3d endPoint, out List <double> bulges)
        {
            var length = endPoint.DistanceTo(insertionPoint);

            bulges = new List <double>();
            var pts = new Point2dCollection();

            if (BreakLineType == BreakLineType.Linear)
            {
                // точки
                if (Overhang > 0)
                {
                    pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(endPoint, insertionPoint, insertionPoint, Overhang * scale));
                    bulges.Add(0.0);
                }

                // Первая точка, соответствующая ручке
                pts.Add(insertionPoint.ConvertPoint3dToPoint2d());
                bulges.Add(0.0);
                pts.Add(ModPlus.Helpers.GeometryHelpers.GetPointToExtendLine(insertionPoint, endPoint, (length / 2) - (BreakWidth / 2.0 * scale)));
                bulges.Add(0.0);
                pts.Add(ModPlus.Helpers.GeometryHelpers.GetPerpendicularPoint2d(
                            insertionPoint,
                            ModPlus.Helpers.GeometryHelpers.ConvertPoint2DToPoint3D(ModPlus.Helpers.GeometryHelpers.GetPointToExtendLine(insertionPoint, endPoint, (length / 2) - (BreakWidth / 4.0 * scale))),
                            BreakHeight / 2.0 * scale));
                bulges.Add(0.0);
                pts.Add(ModPlus.Helpers.GeometryHelpers.GetPerpendicularPoint2d(insertionPoint, ModPlus.Helpers.GeometryHelpers.ConvertPoint2DToPoint3D(
                                                                                    ModPlus.Helpers.GeometryHelpers.GetPointToExtendLine(insertionPoint, endPoint, (length / 2) + (BreakWidth / 4.0 * scale))), -BreakHeight / 2.0 * scale));
                bulges.Add(0.0);
                pts.Add(ModPlus.Helpers.GeometryHelpers.GetPointToExtendLine(insertionPoint, endPoint, (length / 2) + (BreakWidth / 2.0 * scale)));
                bulges.Add(0.0);

                // Конечная точка, соответствующая ручке
                pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(insertionPoint, endPoint, insertionPoint, length));
                bulges.Add(0.0);
                if (Overhang > 0)
                {
                    pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(insertionPoint, endPoint, insertionPoint, length + (Overhang * scale)));
                    bulges.Add(0.0);
                }
            }

            if (BreakLineType == BreakLineType.Curvilinear)
            {
                if (Overhang > 0)
                {
                    pts.Add(ModPlus.Helpers.GeometryHelpers.GetPerpendicularPoint2d(
                                insertionPoint,
                                ModPlus.Helpers.GeometryHelpers.Point3dAtDirection(endPoint, insertionPoint, insertionPoint, Overhang / 100.0 * length),
                                -Overhang / 200.0 * length));
                    bulges.Add(length / 10 / length / 4 * 2);
                }

                // Первая точка, соответствующая ручке
                pts.Add(insertionPoint.ConvertPoint3dToPoint2d());
                bulges.Add(length / 10 / length / 2 * 4);

                // Средняя точка
                pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(insertionPoint, endPoint, insertionPoint, length / 2));
                bulges.Add(-length / 10 / length / 2 * 4);

                // Конечная точка, соответствующая ручке
                pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(insertionPoint, endPoint, insertionPoint, length));
                bulges.Add(0);
                if (Overhang > 0)
                {
                    pts.Add(ModPlus.Helpers.GeometryHelpers.GetPerpendicularPoint2d(
                                insertionPoint,
                                ModPlus.Helpers.GeometryHelpers.Point3dAtDirection(insertionPoint, endPoint, endPoint, Overhang / 100.0 * length),
                                -Overhang / 200.0 * length));
                    bulges.Add(length / 10 / length / 4 * 2);
                }
            }

            if (BreakLineType == BreakLineType.Cylindrical)
            {
                // first
                pts.Add(insertionPoint.ConvertPoint3dToPoint2d());
                bulges.Add(-0.392699081698724);
                pts.Add(ModPlus.Helpers.GeometryHelpers.GetPerpendicularPoint2d(
                            insertionPoint,
                            ModPlus.Helpers.GeometryHelpers.Point3dAtDirection(insertionPoint, endPoint, insertionPoint, length / 10.0),
                            length / 10));
                bulges.Add(-length / 10 / length / 2 * 3);

                // center
                pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(insertionPoint, endPoint, insertionPoint, length / 2));
                bulges.Add(length / 10 / length / 2 * 3);
                pts.Add(ModPlus.Helpers.GeometryHelpers.GetPerpendicularPoint2d(
                            insertionPoint,
                            ModPlus.Helpers.GeometryHelpers.Point3dAtDirection(insertionPoint, endPoint, insertionPoint, length - (length / 10.0)),
                            -length / 10));
                bulges.Add(0.392699081698724);

                // endpoint
                pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(insertionPoint, endPoint, insertionPoint, length));
                bulges.Add(0.392699081698724);
                pts.Add(ModPlus.Helpers.GeometryHelpers.GetPerpendicularPoint2d(
                            insertionPoint,
                            ModPlus.Helpers.GeometryHelpers.Point3dAtDirection(insertionPoint, endPoint, insertionPoint, length - (length / 10.0)),
                            length / 10));
                bulges.Add(length / 10 / length / 2 * 3);
                pts.Add(ModPlus.Helpers.GeometryHelpers.Point2dAtDirection(insertionPoint, endPoint, insertionPoint, length / 2));
                bulges.Add(0.0);
            }

            return(pts);
        }