Beispiel #1
0
        public static void DrawDimension(DrawingContext drawingContext, ElementLayoutAdornerType edge, Matrix matrix, Matrix rootMatrix, Pen pen, Rect bounds, double scale)
        {
            Point point1;
            Point point2;

            switch (edge)
            {
            case ElementLayoutAdornerType.Left:
                point1 = bounds.TopLeft;
                point2 = bounds.BottomLeft;
                break;

            case ElementLayoutAdornerType.Top:
                point1 = bounds.TopLeft;
                point2 = bounds.TopRight;
                break;

            case ElementLayoutAdornerType.Right:
                point1 = bounds.TopRight;
                point2 = bounds.BottomRight;
                break;

            case ElementLayoutAdornerType.Bottom:
                point1 = bounds.BottomLeft;
                point2 = bounds.BottomRight;
                break;

            default:
                throw new NotSupportedException();
            }
            double length  = ((point2 - point1) * rootMatrix).Length;
            Point  point3  = bounds.TopLeft + 0.5 * (bounds.BottomRight - bounds.TopLeft);
            Point  point4  = point1 * matrix;
            Point  point5  = point2 * matrix;
            Point  point6  = point3 * matrix;
            Vector vector1 = point4 + 0.5 * (point5 - point4) - point6;

            vector1.Normalize();
            Vector vector2 = point5 - point4;

            vector2.Normalize();
            Vector overflowDirection = new Vector(vector2.Y, -vector2.X);

            if (overflowDirection * vector1 < 0.0)
            {
                overflowDirection = -overflowDirection;
            }
            Point  point7  = point4 - 0.5 * pen.Thickness * vector2;
            Point  point8  = point5 + 0.5 * pen.Thickness * vector2;
            Vector vector3 = scale * 7.0 * overflowDirection;
            Vector vector4 = scale * 22.0 * overflowDirection;

            drawingContext.DrawLine(pen, point7 + vector3, point7 + vector4);
            drawingContext.DrawLine(pen, point8 + vector3, point8 + vector4);
            Point  a    = point4 + scale * 17.5 * overflowDirection;
            Point  b    = point5 + scale * 17.5 * overflowDirection;
            string text = length.ToString("0.###", (IFormatProvider)CultureInfo.CurrentCulture);

            SizeAdorner.DrawLineAndText(drawingContext, a, b, overflowDirection, pen, pen.Brush, text, scale);
        }
        public override void Draw(DrawingContext ctx, Matrix matrix)
        {
            if (this.Element.ParentElement == null || this.Element.Visual == null)
            {
                return;
            }
            Point pointBegin;
            Point pointEnd;

            this.GetPoints(out pointBegin, out pointEnd);
            string text = string.Empty;

            if (!this.IsAuto)
            {
                Matrix computedTransformToRoot = this.DesignerContext.ActiveView.GetComputedTransformToRoot((SceneElement)this.Element);
                text = ((pointEnd - pointBegin) * computedTransformToRoot).Length.ToString("0.###", (IFormatProvider)CultureInfo.CurrentCulture);
            }
            Point a    = pointBegin * matrix;
            Point b    = pointEnd * matrix;
            Pen   pen1 = this.ThinPen.Clone();

            pen1.Brush.Opacity = 0.5;
            if (this.IsAuto && VectorUtilities.SquaredDistance(a, b) < 10000000000.0)
            {
                pen1.DashStyle = ElementLayoutLineAdorner.LineDashStyle;
            }
            pen1.Freeze();
            Vector overflowDirection = b - a;

            overflowDirection.Normalize();
            SizeAdorner.DrawLineAndText(ctx, a, b, overflowDirection, pen1, this.ActiveBrush, text, 1.0);
            if (this.type != ElementLayoutAdornerType.Left)
            {
                return;
            }
            Transform   transform1  = (Transform)this.Element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty);
            Transform   transform2  = (Transform)null;
            IPropertyId propertyKey = (IPropertyId)this.Element.ProjectContext.ResolveProperty(BaseFrameworkElement.LayoutTransformProperty);

            if (propertyKey != null)
            {
                transform2 = (Transform)this.Element.GetComputedValueAsWpf(propertyKey);
            }
            if ((transform1 == null || transform1.Value.IsIdentity) && (transform2 == null || transform2.Value.IsIdentity))
            {
                return;
            }
            RectangleGeometry rectangleGeometry = new RectangleGeometry(this.DesignerContext.ActiveSceneViewModel.GetLayoutDesignerForChild((SceneElement)this.Element, true).GetChildRect(this.Element), 0.0, 0.0, (Transform) new MatrixTransform(this.Element.GetComputedTransformFromVisualParent() * matrix));

            rectangleGeometry.Freeze();
            Pen pen2 = this.ThinPen.Clone();

            pen2.Brush.Opacity = 0.5;
            pen2.Freeze();
            ctx.DrawGeometry((Brush)null, pen2, (System.Windows.Media.Geometry)rectangleGeometry);
        }