Exemplo n.º 1
0
        private void CreateEntities(
            Point3d insertionPoint,
            Point3d leaderPoint,
            double scale)
        {
            var secantThickness = SecantThickness * scale;
            var secantLength    = SecantLength * scale;
            var v = (leaderPoint - insertionPoint).GetNormal();

            var secantEnd = insertionPoint + (v * secantLength);

            _secantPolyline = new Polyline(2);
            _secantPolyline.AddVertexAt(0, insertionPoint.ToPoint2d(), 0.0, secantThickness, secantThickness);
            _secantPolyline.AddVertexAt(1, secantEnd.ToPoint2d(), 0.0, secantThickness, secantThickness);

            if (secantEnd.DistanceTo(leaderPoint) > 0.0)
            {
                _leaderLine = new Line(secantEnd, leaderPoint);
            }

            //// Дальше код идентичен коду в NodalLeader! Учесть при внесении изменений

            SetNodeNumberOnCreation();

            var mainTextHeight     = MainTextHeight * scale;
            var secondTextHeight   = SecondTextHeight * scale;
            var textIndent         = TextIndent * scale;
            var textVerticalOffset = TextVerticalOffset * scale;
            var shelfLedge         = ShelfLedge * scale;
            var isRight            = ShelfPosition == ShelfPosition.Right;

            var topFirstTextLength  = 0.0;
            var topSecondTextLength = 0.0;
            var bottomTextLength    = 0.0;
            var bottomTextHeight    = 0.0;

            if (!string.IsNullOrEmpty(NodeNumber))
            {
                _topFirstDbText = new DBText {
                    TextString = NodeNumber
                };
                _topFirstDbText.SetProperties(TextStyle, mainTextHeight);
                topFirstTextLength = _topFirstDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(SheetNumber))
            {
                _topSecondDbText = new DBText {
                    TextString = $"({SheetNumber})"
                };
                _topSecondDbText.SetProperties(TextStyle, secondTextHeight);
                topSecondTextLength = _topSecondDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(NodeAddress))
            {
                _bottomDbText = new DBText {
                    TextString = NodeAddress
                };
                _bottomDbText.SetProperties(TextStyle, secondTextHeight);
                bottomTextLength = _bottomDbText.GetLength();
                bottomTextHeight = _bottomDbText.GetHeight();
            }

            var topTextLength     = topFirstTextLength + topSecondTextLength;
            var largestTextLength = Math.Max(topTextLength, bottomTextLength);
            var shelfLength       = textIndent + largestTextLength + shelfLedge;

            if (isRight)
            {
                var nodeNumberPosition =
                    leaderPoint +
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = nodeNumberPosition;
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = nodeNumberPosition + (Vector3d.XAxis * topFirstTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }
            else
            {
                var sheetNumberEndPoint =
                    leaderPoint -
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = sheetNumberEndPoint -
                                               (Vector3d.XAxis * (topSecondTextLength + topFirstTextLength));
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = sheetNumberEndPoint -
                                                (Vector3d.XAxis * topSecondTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint -
                                             (Vector3d.XAxis * shelfLength) +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }

            var shelfEndPoint = ShelfPosition == ShelfPosition.Right
                ? leaderPoint + (Vector3d.XAxis * shelfLength)
                : leaderPoint - (Vector3d.XAxis * shelfLength);

            if (HideTextBackground)
            {
                var offset = TextMaskOffset * scale;
                _topFirstTextMask  = _topFirstDbText.GetBackgroundMask(offset);
                _topSecondTextMask = _topSecondDbText.GetBackgroundMask(offset);
                _bottomTextMask    = _bottomDbText.GetBackgroundMask(offset);
            }

            if (IsTextAlwaysHorizontal && IsRotated)
            {
                var backRotationMatrix = GetBackRotationMatrix(leaderPoint);
                shelfEndPoint = shelfEndPoint.TransformBy(backRotationMatrix);
                _topFirstDbText?.TransformBy(backRotationMatrix);
                _topFirstTextMask?.TransformBy(backRotationMatrix);
                _topSecondDbText?.TransformBy(backRotationMatrix);
                _topSecondTextMask?.TransformBy(backRotationMatrix);
                _bottomDbText?.TransformBy(backRotationMatrix);
                _bottomTextMask?.TransformBy(backRotationMatrix);
            }

            _shelfLine = new Line(leaderPoint, shelfEndPoint);
        }
Exemplo n.º 2
0
        private void CreateEntities(
            Point3d insertionPoint,
            Point3d framePoint,
            Point3d leaderPoint,
            double scale,
            bool drawLeader)
        {
            if (FrameType == FrameType.Round)
            {
                _framePolyline = null;

                try
                {
                    var radius = framePoint.DistanceTo(insertionPoint);
                    if (double.IsNaN(radius) || double.IsInfinity(radius) || radius < 0.0)
                    {
                        radius = 5 * scale;
                    }

                    _frameCircle = new Circle
                    {
                        Center = insertionPoint,
                        Radius = radius
                    };

                    if (!drawLeader)
                    {
                        return;
                    }

                    var leaderLine = new Line(insertionPoint, leaderPoint);
                    var pts        = new Point3dCollection();
                    _frameCircle.IntersectWith(leaderLine, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero);
                    _leaderLine = pts.Count > 0 ? new Line(pts[0], leaderPoint) : leaderLine;
                }
                catch
                {
                    _frameCircle = null;
                }
            }
            else
            {
                _frameCircle = null;

                var width        = Math.Abs(framePoint.X - insertionPoint.X);
                var height       = Math.Abs(framePoint.Y - insertionPoint.Y);
                var cornerRadius = CornerRadius * scale;

                if (((width * 2) - (cornerRadius * 2)) < (1 * scale) ||
                    ((height * 2) - (cornerRadius * 2)) < (1 * scale))
                {
                    var minSize = Math.Min(width * 2, height * 2);
                    cornerRadius = (int)((minSize - (1 * scale)) / 2);
                }

                var points = new[]
                {
                    new Point2d(insertionPoint.X - width + cornerRadius, insertionPoint.Y - height),
                    new Point2d(insertionPoint.X - width, insertionPoint.Y - height + cornerRadius),
                    new Point2d(insertionPoint.X - width, insertionPoint.Y + height - cornerRadius),
                    new Point2d(insertionPoint.X - width + cornerRadius, insertionPoint.Y + height),
                    new Point2d(insertionPoint.X + width - cornerRadius, insertionPoint.Y + height),
                    new Point2d(insertionPoint.X + width, insertionPoint.Y + height - cornerRadius),
                    new Point2d(insertionPoint.X + width, insertionPoint.Y - height + cornerRadius),
                    new Point2d(insertionPoint.X + width - cornerRadius, insertionPoint.Y - height)
                };

                var bevelBulge = Math.Tan((90 / 4).DegreeToRadian());
                var bulges     = new[]
                {
                    -bevelBulge,
                    0.0,
                    -bevelBulge,
                    0.0,
                    -bevelBulge,
                    0.0,
                    -bevelBulge,
                    0.0
                };

                _framePolyline = new Polyline(points.Length);

                for (var i = 0; i < points.Length; i++)
                {
                    _framePolyline.AddVertexAt(i, points[i], bulges[i], 0.0, 0.0);
                }

                _framePolyline.Closed = true;

                if (!drawLeader)
                {
                    return;
                }

                var leaderLine = new Line(insertionPoint, leaderPoint);
                var pts        = new Point3dCollection();
                _framePolyline.IntersectWith(leaderLine, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero);
                _leaderLine = pts.Count > 0 ? new Line(pts[0], leaderPoint) : leaderLine;
            }

            // Если drawLeader == false, то дальше код не выполнится

            //// Дальше код идентичен коду в SecantNodalLeader! Учесть при внесении изменений

            SetNodeNumberOnCreation();

            var mainTextHeight     = MainTextHeight * scale;
            var secondTextHeight   = SecondTextHeight * scale;
            var textIndent         = TextIndent * scale;
            var textVerticalOffset = TextVerticalOffset * scale;
            var shelfLedge         = ShelfLedge * scale;
            var isRight            = ShelfPosition == ShelfPosition.Right;

            var topFirstTextLength  = 0.0;
            var topSecondTextLength = 0.0;
            var bottomTextLength    = 0.0;
            var bottomTextHeight    = 0.0;

            if (!string.IsNullOrEmpty(NodeNumber))
            {
                _topFirstDbText = new DBText {
                    TextString = NodeNumber
                };
                _topFirstDbText.SetProperties(TextStyle, mainTextHeight);
                topFirstTextLength = _topFirstDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(SheetNumber))
            {
                _topSecondDbText = new DBText {
                    TextString = $"({SheetNumber})"
                };
                _topSecondDbText.SetProperties(TextStyle, secondTextHeight);
                topSecondTextLength = _topSecondDbText.GetLength();
            }

            if (!string.IsNullOrEmpty(NodeAddress))
            {
                _bottomDbText = new DBText {
                    TextString = NodeAddress
                };
                _bottomDbText.SetProperties(TextStyle, secondTextHeight);
                bottomTextLength = _bottomDbText.GetLength();
                bottomTextHeight = _bottomDbText.GetHeight();
            }

            var topTextLength     = topFirstTextLength + topSecondTextLength;
            var largestTextLength = Math.Max(topTextLength, bottomTextLength);
            var shelfLength       = textIndent + largestTextLength + shelfLedge;

            if (isRight)
            {
                var nodeNumberPosition =
                    leaderPoint +
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = nodeNumberPosition;
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = nodeNumberPosition + (Vector3d.XAxis * topFirstTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }
            else
            {
                var sheetNumberEndPoint =
                    leaderPoint -
                    (Vector3d.XAxis * (shelfLength - topTextLength) / 2) +
                    (Vector3d.YAxis * textVerticalOffset);

                if (_topFirstDbText != null)
                {
                    _topFirstDbText.Position = sheetNumberEndPoint -
                                               (Vector3d.XAxis * (topSecondTextLength + topFirstTextLength));
                }

                if (_topSecondDbText != null)
                {
                    _topSecondDbText.Position = sheetNumberEndPoint -
                                                (Vector3d.XAxis * topSecondTextLength);
                }

                if (_bottomDbText != null)
                {
                    _bottomDbText.Position = leaderPoint -
                                             (Vector3d.XAxis * shelfLength) +
                                             (Vector3d.XAxis * (shelfLength - bottomTextLength) / 2) -
                                             (Vector3d.YAxis * (textVerticalOffset + bottomTextHeight));
                }
            }

            var shelfEndPoint = ShelfPosition == ShelfPosition.Right
                ? leaderPoint + (Vector3d.XAxis * shelfLength)
                : leaderPoint - (Vector3d.XAxis * shelfLength);

            if (HideTextBackground)
            {
                var offset = TextMaskOffset * scale;
                _topFirstTextMask  = _topFirstDbText.GetBackgroundMask(offset);
                _topSecondTextMask = _topSecondDbText.GetBackgroundMask(offset);
                _bottomTextMask    = _bottomDbText.GetBackgroundMask(offset);
            }

            if (IsTextAlwaysHorizontal && IsRotated)
            {
                var backRotationMatrix = GetBackRotationMatrix(leaderPoint);
                shelfEndPoint = shelfEndPoint.TransformBy(backRotationMatrix);
                _topFirstDbText?.TransformBy(backRotationMatrix);
                _topFirstTextMask?.TransformBy(backRotationMatrix);
                _topSecondDbText?.TransformBy(backRotationMatrix);
                _topSecondTextMask?.TransformBy(backRotationMatrix);
                _bottomDbText?.TransformBy(backRotationMatrix);
                _bottomTextMask?.TransformBy(backRotationMatrix);
            }

            _shelfLine = new Line(leaderPoint, shelfEndPoint);
        }