Exemplo n.º 1
0
        private GraphicInstance CreateGraphicVisualizedInstance(Type type, LogicalInstance logicalInstance, DragEventArgs args)
        {
            Point           position        = args.GetPosition(this);
            double          width           = (double)type.GetProperty("Width").GetValue(Activator.CreateInstance(type), null);
            double          height          = (double)type.GetProperty("Height").GetValue(Activator.CreateInstance(type), null);
            GraphicInstance graphicInstance = null;

            if (type.IsSubclassOf(typeof(NodeType)))
            {
                ParentableInstance parent = (this.Content as CanvasItemsControl).FindParent(position, graphicInstance);
                graphicInstance = new NodeInstance
                {
                    X               = position.X,
                    Y               = position.Y,
                    Width           = (width != 0 && !double.IsNaN(width)) ? width : 200,
                    Height          = (height != 0 && !double.IsNaN(height)) ? height : 200,
                    LogicalInstance = logicalInstance,
                    Parent          = parent
                };
            }
            else
            {
                graphicInstance = new EdgeInstance
                {
                    X               = position.X,
                    Y               = position.Y,
                    Width           = (width != 0 && !double.IsNaN(width)) ? width : 200,
                    Height          = (height != 0 && !double.IsNaN(height)) ? height : 200,
                    LogicalInstance = logicalInstance,
                    Parent          = InstancesManager.Instance.CanvasRootElement
                };
            }
            return(graphicInstance);
        }
Exemplo n.º 2
0
 private void AddNodeChildren(ParentableInstance parentableInstance)
 {
     foreach (var entity in parentableInstance.NodeChildren)
     {
         CanvasInstancesSource.Add(entity);
         AddNodeChildren(entity);
     }
 }
Exemplo n.º 3
0
        private void ObjectTypeMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            GraphicInstance dataContext = (sender as ObjectType).DataContext as GraphicInstance;

            if (dataContext is NodeInstance)
            {
                Point position            = e.GetPosition(this);
                ParentableInstance parent = FindParent(position, dataContext);
                ((sender as ObjectType).DataContext as NodeInstance).Parent = parent;
                if (parent is NodeInstance)
                {
                    Point positionInParent = new Point((dataContext as NodeInstance).X - (parent as NodeInstance).X,
                                                       (dataContext as NodeInstance).Y - (parent as NodeInstance).Y);
                    (parent as NodeInstance).Width  = Math.Max(positionInParent.X + (dataContext as NodeInstance).Width + 5, (parent as NodeInstance).Width);
                    (parent as NodeInstance).Height = Math.Max(positionInParent.Y + (dataContext as NodeInstance).Height + 5, (parent as NodeInstance).Height);
                }
            }
        }