Esempio n. 1
0
        public void DrawWireFromConnector(Image dot, string name, ElementControl ec, List <Dot> dList)
        {
            if (!ec.GetConnectionAvailability(name) && !isDotOccupied(dot, dList))
            {
                if (!turn && previousElementName != name)
                {
                    Polyline pl = CreatePolyline();

                    Panel.SetZIndex(pl, 0);

                    previousElementName = name;
                    previousDotName     = dot.Tag.ToString();

                    previousLine = pl;
                    previousDot  = dot;

                    turn = true;

                    BeginDrawing();
                }
                else
                {
                    turn = false;
                    canvas.Children.Remove(previousLine);

                    previousLine        = null;
                    previousDot         = null;
                    previousElementName = "";
                    previousDotName     = "";
                }
            }
            else
            {
                foreach (SpecificElement se in lc.ec.GetAllElements())
                {
                    if (se.GetName() == name)
                    {
                        if (ec.GetConnectionAvailability(name))
                        {
                            mgc.ShowWarningMessage(se.GetElement(), "This element has max connections used");
                        }
                        else if (isDotOccupied(dot, dList))
                        {
                            mgc.ShowWarningMessage(se.GetElement(), "This dot is being used by another wire");
                        }
                    }
                }
            }
        }
        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Image draggableControl = sender as Image;

            if (!Keyboard.IsKeyDown(Key.W) && !Keyboard.IsKeyDown(Key.C) && !Keyboard.IsKeyDown(Key.X) && modeTool != "delete")
            {
                dgc.UpadateDotsLocation(draggableControl, lc.ec);
                //highlighting_rectangle.Visibility = Visibility.Hidden;
                if (mngc.elementBehaviour != "neverGrid")
                {
                    SnapToClosestCell(draggableControl);
                }
                originTT      = draggableControl.RenderTransform as TranslateTransform ?? new TranslateTransform();
                isDragging    = true;
                clickPosition = e.GetPosition(form);
                draggableControl.CaptureMouse();

                startPosition = Mouse.GetPosition(form);
                dgc.BeginHide(startPosition, lc.ec.GetDots(draggableControl.Tag.ToString()));
            }
            if (Keyboard.IsKeyDown(Key.X) || modeTool == "delete")
            {
                if (!wgc.turn)
                {
                    DeleteElement(draggableControl);
                }
                else
                {
                    mgc.ShowWarningMessage(draggableControl, "Wiring process \n detected!");
                }
            }
            if (Keyboard.IsKeyDown(Key.C) || modeTool == "info")
            {
                mgc.ShowPopupMessage(draggableControl);
            }
        }