Example #1
0
        public void drawOnCanvas(Point position)
        {
            attachMovingEvents(currentEntity);

            Canvas.SetLeft(currentEntity, position.X + X_OFFSET);
            Canvas.SetTop(currentEntity, position.Y + Y_OFFSET);

            currentCanvas.Children.Add(currentEntity);
            currentEntity.createAndDraw(position.X + X_OFFSET, position.Y + Y_OFFSET);

            ZIndexUtil.setCorrectZIndex(currentCanvas, currentEntity);

            foreach (Port p in currentEntity.getPorts())
            {
                p.MouseLeftButtonDown += Shape_MouseLeftButtonDown;
                p.MouseLeftButtonUp   += Shape_MouseLeftButtonUp;
            }

            if (!(currentEntity is SubDiagram))
            {
                currentEntity = Activator.CreateInstance(currentEntity.GetType(), currentCanvas) as UIEntity;
            }
            else
            {
                currentEntity = Activator.CreateInstance(currentEntity.GetType(), currentCanvas,
                                                         (currentEntity as SubDiagram).ProjectItem) as UIEntity;
            }

            ModelChanged();
        }
Example #2
0
        private void connect()
        {
            UndoRedoManager.putInUndoStack(currentEntity);
            UndoRedoManager.clearRedoStack(currentEntity);


            if (firstConnect)
            {
                setBinding(ConnectionLine.SourceProperty);
                firstConnect = false;
            }
            else if (canConnect())
            {
                setBinding(ConnectionLine.DestinationProperty);

                currentEntity.MouseLeftButtonDown += Shape_MouseLeftButtonDown;
                currentEntity.MouseLeftButtonUp   += Shape_MouseLeftButtonUp;

                ZIndexUtil.setCorrectZIndex(currentCanvas, currentEntity);

                currentCanvas.Children.Add(currentEntity);
                currentEntity = Activator.CreateInstance(currentEntity.GetType(), currentCanvas) as UIEntity;
                firstConnect  = true;
                ModelChanged();
            }
        }
Example #3
0
        public void updateText(string newText)
        {
            if (label != null)
            {
                canvas.Children.Remove(label);
                CoordinatesHandler ch = getMovingCoordinate(label);
                label = new Label(this, canvas, ch.xShape, ch.yShape, newText);

                // dirty hack :(
                if (this is Label)
                {
                    ((MainWindow)System.Windows.Application.Current.MainWindow).attachMovingEvents(label);
                }

                canvas.Children.Add(label);
                ZIndexUtil.setCorrectZIndex(canvas, this);
            }
        }
Example #4
0
 public ScrollableCanvas(SerializationInfo info, StreamingContext context)
 {
     for (int i = 0; i < info.MemberCount - 1; i++)
     {
         UIEntity ent = info.GetValue("Child" + i, typeof(UIEntity)) as UIEntity;
         try
         {
             // hack for copy paste serialization
             if (ent.EntityName != null)
             {
                 Children.Add(ent);
                 ZIndexUtil.setCorrectZIndex(this, ent);
             }
         }
         catch (Exception ex)
         {
             Console.Out.Write(ex);
         }
     }
     this.id = info.GetInt32("id");
 }
Example #5
0
        private void PasteComand(object sender, ExecutedRoutedEventArgs e)
        {
            UndoRedoManager.putInUndoStack((ScrollableCanvas)currentCanvas);
            UndoRedoManager.clearRedoStack((ScrollableCanvas)currentCanvas);

            IDataObject dataObj = Clipboard.GetDataObject();
            string      format  = typeof(UIEntity).FullName;

            format = DataFormats.Serializable;

            if (dataObj.GetDataPresent(format))
            {
                try
                {
                    UIEntity obj = (UIEntity)dataObj.GetData(format);
                    obj.canvas.Children.Clear();
                    obj.canvas = currentCanvas;

                    foreach (Port p in obj.getPorts())
                    {
                        p.canvas = currentCanvas;
                    }

                    obj.Label.canvas = currentCanvas;

                    currentEntity = obj;
                    drawOnCanvas(new Point(320, 120));

                    ZIndexUtil.setCorrectZIndex(currentCanvas, obj);
                    currentEntity = null;
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine(ex);
                }
            }
        }
Example #6
0
        private void restoreConnectionLines(MainWindow mw)
        {
            List <ConnectionLine> connections = ConnectorFinder.find(owner.canvas.Children, owner);

            foreach (ConnectionLine cl in connections)
            {
                // can use ==, because it's same object instance
                UIEntity connectedTo = cl.SourcePort.Owner != owner ? cl.SourcePort.Owner : cl.DestinationPort.Owner;
                PortType srcPortType = cl.SourcePort.Owner != owner ? cl.SourcePort.PortType : cl.DestinationPort.PortType;
                PortType dstPortType = cl.SourcePort.Owner != owner ? cl.DestinationPort.PortType : cl.SourcePort.PortType;

                if (!(ParameterProccesor.newResource.GetType() == typeof(MaterialResource) && PortType.BOTTOM_RESOURCE.Equals(dstPortType)))
                {
                    ConnectionLine newCl = new ConnectionLine(owner.canvas);

                    newCl.SetBinding(ConnectionLine.SourceProperty, new Binding()
                    {
                        Source = connectedTo.findPort(srcPortType),
                        Path   = new PropertyPath(Port.AnchorPointProperty)
                    });
                    newCl.SetBinding(ConnectionLine.DestinationProperty, new Binding()
                    {
                        Source = ParameterProccesor.newResource.findPort(dstPortType),
                        Path   = new PropertyPath(Port.AnchorPointProperty)
                    });


                    newCl.MouseLeftButtonDown += mw.Shape_MouseLeftButtonDown;
                    newCl.MouseLeftButtonUp   += mw.Shape_MouseLeftButtonUp;

                    ZIndexUtil.setCorrectZIndex(newCl.canvas, newCl);

                    owner.canvas.Children.Add(newCl);
                }
            }
        }