Esempio n. 1
0
        public static void BindShapeProperties(this IMountLocation self, System.Windows.Shapes.Shape control, Dispatcher dispatcher, Brush fill, Stroke stroke)
        {
            self.BindNativeProperty(dispatcher, "fill.Color", fill, f => control.Fill = new SolidColorBrush(f.ToColor()));

            self.BindNativeProperty(dispatcher, "stroke.Brush.Color", stroke.Brush, s => control.Stroke            = new SolidColorBrush(s.ToColor()));
            self.BindNativeProperty(dispatcher, "stroke.Thickness", stroke.Thickness, s => control.StrokeThickness = s);
            self.BindNativeProperty(dispatcher, "stroke.DashArray", stroke.DashArray, s => control.StrokeDashArray = s.ToDashArray());
        }
Esempio n. 2
0
        public Shape(Color color, Point p1, Point p2)
        {
            this.color = color;
            this.p1    = p1;

            SetP2X(p2);
            SetP2Y(p2);

            dBase = GenerateDrawBase();
            StartPosSet();

            FillFig();
            SideSet();
        }
Esempio n. 3
0
        protected Shape(SerializationInfo info, StreamingContext context)
        {
            this.color = (Color)info.GetValue("color", typeof(Color));
            this.p1    = (Point)info.GetValue("point1", typeof(Point));
            this.p2    = (Point)info.GetValue("point2", typeof(Point));

            SetP2X(p2);
            SetP2Y(p2);

            dBase = GenerateDrawBase();
            StartPosSet();

            FillFig();
            SideSet();
        }
Esempio n. 4
0
        private void OnMouseDownFigure(object sender, MouseEventArgs e)
        {
            var p = e.GetPosition(CanvasMain);

            _chousenShape = (System.Windows.Shapes.Shape)sender;


            if (_shape.Figures.All(x => x.Tag != _chousenShape.GetHashCode()))
            {
                return;
            }

            _figure         = _shape.Figures.First(x => x.Tag == _chousenShape.GetHashCode());
            _figure.Tag     = CanvasMain.Children.IndexOf(_chousenShape);
            _isMove         = _isOneFigure = true;
            _oldPointFirst  = _figure.FirstPoint;
            _oldPointSecond = _figure.SecondPoint;
            _x1             = p.X;
            _y1             = p.Y;
        }
Esempio n. 5
0
        /// <summary>
        /// Sets pen properties to the stroke properties.
        /// </summary>
        /// <param name="shape">WPF shape object.</param>
        /// <param name="pen">Pen object.</param>
        internal static void SetPen(this System.Windows.Shapes.Shape shape, IPen pen)
        {
            var uiPen = (pen as Pen)?.UIPen;

            if (uiPen != null)
            {
                shape.Stroke          = uiPen.Brush;
                shape.StrokeThickness = uiPen.Thickness;
                shape.StrokeDashCap   = uiPen.DashCap;
                if (uiPen.DashStyle != null)
                {
                    shape.StrokeDashArray  = uiPen.DashStyle.Dashes;
                    shape.StrokeDashOffset = uiPen.DashStyle.Offset;
                }
                shape.StrokeStartLineCap = uiPen.StartLineCap;
                shape.StrokeEndLineCap   = uiPen.EndLineCap;
                shape.StrokeLineJoin     = uiPen.LineJoin;
                shape.StrokeMiterLimit   = uiPen.MiterLimit;
            }
        }
        public static void Entity2Shape(netDxf.Entities.EntityObject xEntity, System.Windows.Shapes.Shape wShape)
        {
            double dThickness = xEntity.getLineweightValue();
            double dScale     = xEntity.LinetypeScale;

            /* By Block */
            if (dThickness == -2)
            {
                dThickness = xEntity.Owner.Layer.getLineweightValue();
            }
            if (dScale == -2)
            {
                dScale = 1;
            }


            /* By Default */
            if (dThickness == -3)
            {
                dThickness = defaultThickness;
            }
            if (dScale == -3)
            {
                dScale = 1;
            }

            /*Debug.WriteLine("dThickness="+dThickness);*/
            /*Debug.WriteLine("dThickness="+dThickness+" dScale="+dScale);*/

            wShape.StrokeThickness = (dThickness > 0) ? dThickness * dScale * 3.4 : 0.1;

            DoubleCollection myCollec = new DoubleCollection(xEntity.Linetype.Segments.ToArray());

            wShape.StrokeDashArray = myCollec;

            AciColor myColor = xEntity.getColor();

            wShape.Stroke = new SolidColorBrush(TypeConverter.ToMediaColor(myColor.ToColor()));
        }
        /// <summary>
        /// Paints the endpoint to screen
        /// Precondition: Graphics.PageUnit = GraphicsUnit.Pixel
        /// Precondition: Graphics.SmoothingMode = SmoothingMode.AntiAlias
        /// </summary>
        public void PaintMe()
        {
            if (Double.IsInfinity(InkPoint.Y))
            {
                InkPoint.Y = 100;
            }
            if (Double.IsInfinity(InkPoint.X))
            {
                InkPoint.X = 100;
            }

            Clear();

            if (updateShape)
            {
                // Get Endpoint Shape
                if (endPoint.InternalEndPoint)
                {
                    if (debug)
                    {
                        Console.WriteLine("Internal Endpoint");
                    }

                    // Don't draw for now, but you can have a small transparent circle (or any other shape)
                    //PointShape = Internal();
                }
                else if (Type == EndPointType.ConnectedToSymbol || Type == EndPointType.ConnectedToWire || Type == EndPointType.ConnectedToLabel)
                {
                    if (debug)
                    {
                        Console.WriteLine("Connected");
                    }

                    PointShape = Valid();
                }
                else if (Type == EndPointType.Unconnected)
                {
                    if (debug)
                    {
                        Console.WriteLine("Unconnected");
                    }

                    PointShape = Invalid();
                }
                else
                {
                    if (debug)
                    {
                        Console.WriteLine("Connection unknown");
                    }

                    PointShape = Unknown();
                }

                updateShape = false;
            }

            // If we're not drawing this endpoint, don't try to draw it!
            if (PointShape == null)
            {
                return;
            }

            InkCanvas.SetTop(PointShape, InkPoint.Y - HEIGHT / 2);
            InkCanvas.SetLeft(PointShape, InkPoint.X - WIDTH / 2);

            // Add rect to Picture
            if (!inkCanvas.Children.Contains(PointShape))
            {
                inkCanvas.Children.Add(PointShape);
            }
            PointShape.Visibility = System.Windows.Visibility.Visible;
        }
        void UpdateCallOrderByItem(System.Windows.Shapes.Shape item,
                                   ref Dictionary <Tuple <string, string>, OrderData> orderEdge, bool onlyMarkRightSide = false)
        {
            // Select node item
            var scene          = UIManager.Instance().GetScene();
            var itemDict       = scene.GetItemDict();
            var isEdgeSelected = false;
            var edgeItem       = item as CodeUIEdgeItem;

            if (edgeItem != null)
            {
                isEdgeSelected = true;
                if (itemDict.ContainsKey(edgeItem.m_srcUniqueName) &&
                    itemDict.ContainsKey(edgeItem.m_tarUniqueName))
                {
                    var srcItem = itemDict[edgeItem.m_srcUniqueName];
                    var dstItem = itemDict[edgeItem.m_tarUniqueName];
                    srcItem.m_isConnectedToFocusNode = true;
                    dstItem.m_isConnectedToFocusNode = true;
                    item = srcItem;
                }
            }

            var nodeItem = item as CodeUIItem;

            if (nodeItem == null)
            {
                return;
            }

            // Mark connected edges and nodes
            var edgeDict       = scene.GetEdgeDict();
            var itemUniqueName = nodeItem.GetUniqueName();

            foreach (var edgePair in edgeDict)
            {
                var key     = edgePair.Key;
                var edge    = edgePair.Value;
                var srcItem = itemDict[key.Item1];
                var tarItem = itemDict[key.Item2];
                edge.m_isConnectedToFocusNode = key.Item1 == itemUniqueName || key.Item2 == itemUniqueName;

                if (isEdgeSelected == false)
                {
                    if (key.Item1 == itemUniqueName)// && tarItem.IsFunction())
                    {
                        tarItem.m_isConnectedToFocusNode = true;
                    }
                    if (!onlyMarkRightSide && key.Item2 == itemUniqueName)// && srcItem.IsFunction())
                    {
                        srcItem.m_isConnectedToFocusNode = true;
                    }
                }
            }

            if (!nodeItem.IsFunction())
            {
                return;
            }

            // Collect candidate edges
            var    edgeList  = new List <CodeUIEdgeItem>();
            double minXRange = double.MaxValue;
            double maxXRange = double.MinValue;

            foreach (var edgePair in edgeDict)
            {
                var key     = edgePair.Key;
                var edge    = edgePair.Value;
                var srcItem = itemDict[key.Item1];
                var tarItem = itemDict[key.Item2];
                if (key.Item1 == itemUniqueName)// && tarItem.IsFunction())
                {
                    edgeList.Add(edge);
                    Point srcPos, tarPos;
                    edge.GetNodePos(out srcPos, out tarPos);
                    minXRange = Math.Min(tarPos.X, minXRange);
                    maxXRange = Math.Max(tarPos.X, maxXRange);
                }
            }

            if (edgeList.Count <= 1)
            {
                return;
            }
            double basePos = 0.0;
            double itemX   = nodeItem.Pos.X;

            if (minXRange < itemX && maxXRange > itemX)
            {
                basePos = double.NaN;
            }
            else if (minXRange >= itemX)
            {
                basePos = minXRange;
            }
            else if (maxXRange <= itemX)
            {
                basePos = maxXRange;
            }

            // Find edge order
            bool   isSorted = false;
            string bodyCode = nodeItem.m_bodyCode;

            if (bodyCode != null && bodyCode != "")
            {
                var nodeDict    = scene.GetItemDict();
                var edgePosList = new List <Tuple <CodeUIEdgeItem, int> >();
                foreach (var edge in edgeList)
                {
                    var    tarItem            = nodeDict[edge.m_tarUniqueName];
                    string indentifierPattern = string.Format(@"\b{0}\b", tarItem.GetName());

                    try
                    {
                        var match = Regex.Match(bodyCode, indentifierPattern, RegexOptions.ExplicitCapture);

                        if (match.Success)
                        {
                            edgePosList.Add(new Tuple <CodeUIEdgeItem, int>(edge, match.Index));
                        }
                        else
                        {
                            edgePosList.Add(new Tuple <CodeUIEdgeItem, int>(edge, -1));
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                edgePosList.Sort((x, y) => x.Item2.CompareTo(y.Item2));
                edgeList.Clear();
                foreach (var edgePair in edgePosList)
                {
                    edgeList.Add(edgePair.Item1);
                }
                isSorted = true;
            }

            // Sort edges
            if (!isSorted)
            {
                edgeList.Sort((x, y) => x.ComparePos(y));
            }

            // Build call order data
            for (int i = 0; i < edgeList.Count; i++)
            {
                var   edge = edgeList[i];
                Point srcPos, tarPos;
                edge.GetNodePos(out srcPos, out tarPos);
                double padding = srcPos.X < tarPos.X ? -12.0 : 12.0;
                double x, y;
                if (double.IsNaN(basePos))
                {
                    x = tarPos.X + padding;
                }
                else
                {
                    x = basePos + padding;
                }
                y = edge.FindCurveYPos(x);
                orderEdge[new Tuple <string, string>(edge.m_srcUniqueName, edge.m_tarUniqueName)] =
                    new OrderData(i + 1, new Point(x, y));
                //edge.m_orderData = new OrderData(i + 1, new Point(x, y));
            }
        }
        public static void Entity2Shape(EntityObject xEntity, System.Windows.Shapes.Shape wShape)
        {
            //double dThickness = xEntity.getLineweightValue();
            //double dScale = xEntity.LinetypeScale;

            var    it         = xEntity.Lineweight;
            double dThickness = 0;

            switch (it)
            {
            case Lineweight.ByBlock:
                dThickness = -2;
                break;

            case Lineweight.ByLayer:
                dThickness = -1;
                break;

            case Lineweight.Default:
                dThickness = -3;
                break;

            default:
                var LW = xEntity.Lineweight.ToString().Replace("W", "");
                dThickness = double.Parse(LW);
                break;
            }


            double dScale = xEntity.LinetypeScale;

            /* By Block */
            if (dThickness == -2)
            {
                dThickness = double.Parse(xEntity.Owner.Layer.Lineweight.ToString());   //xEntity.Owner.Layer.getLineweightValue();
            }
            if (dScale == -2)
            {
                dScale = 1;
            }


            /* By Default */
            if (dThickness == -3)
            {
                dThickness = defaultThickness;
            }
            if (dScale == -3)
            {
                dScale = 1;
            }

            /*Debug.WriteLine("dThickness="+dThickness);*/
            /*Debug.WriteLine("dThickness="+dThickness+" dScale="+dScale);*/

            wShape.StrokeThickness = (dThickness > 0) ? dThickness * dScale * 3.4 : 0.1;

            List <double> listdouble = new List <double>();//改写

            for (int i = 0; i < xEntity.Linetype.Segments.Count; i++)
            {
                Double T = xEntity.Linetype.Segments[i].Length;
                listdouble.Add(T);
            }
            DoubleCollection myCollec = new DoubleCollection(listdouble.ToArray());

            wShape.StrokeDashArray = myCollec;

            AciColor myColor = xEntity.Color;

            wShape.Stroke = new SolidColorBrush(TypeConverter.ToMediaColor(myColor.ToColor()));
        }
 public static void PaintBackColor(System.Windows.Shapes.Shape sender, bool rigth)
 {
     sender.Fill = new SolidColorBrush(rigth ? Const.CorrectColor : Const.IncorrectColor);
 }
 private void undraw_shape(System.Windows.Shapes.Shape shape)
 {
     canvas.Children.Remove(shape);
 }
Esempio n. 12
0
        /// <summary>
        /// 播放动画()
        /// </summary>
        /// <param name="from">From</param>
        /// <param name="to">To</param>
        /// <param name="dp">依赖属性</param>
        /// <param name="target">对象</param>
        /// <param name="duration">时长</param>
        public static void PlayAnimation(double from, double to, DependencyProperty dp, System.Windows.Shapes.Shape target, double duration = 1)
        {
            DoubleAnimation animation = new DoubleAnimation()
            {
                From              = from,
                To                = to,
                Duration          = TimeSpan.FromSeconds(duration),
                FillBehavior      = FillBehavior.HoldEnd,
                AccelerationRatio = .5,
                EasingFunction    = CAAnimation.be
            };

            target.BeginAnimation(dp, animation);
        }