示例#1
0
        private void ContentPresenterLoaded(object sender, RoutedEventArgs e)
        {
            ContentPresenter contentPresenter = sender as ContentPresenter;
            GraphicInstance  graphicInstance  = contentPresenter.Content as GraphicInstance;
            LogicalInstance  logicalInstance  = graphicInstance.LogicalInstance;

            TypesManager.Instance.InitProperties(logicalInstance);
            Canvas     itemsCanvas = VisualTreeHelper.GetChild(contentPresenter, 0) as Canvas;
            ObjectType objectType  = VisualTreeHelper.GetChild(itemsCanvas, 0) as ObjectType;

            SetPropertyBindings(logicalInstance, objectType);
            objectType.Clicked += new ClickHandler(ObjectTypeClicked);
            Binding bindingSelected = new Binding
            {
                Mode      = BindingMode.TwoWay,
                Path      = new PropertyPath("SelectedGraphicInstance"),
                Source    = UIManager.Instance,
                Converter = new IdToSelectedConverter(objectType)
            };

            objectType.SetBinding(ObjectType.SelectedProperty, bindingSelected);
            objectType.ZIndexChanged     += new ZIndexChangedHandler(ObjectTypeZIndexChanged);
            objectType.MouseLeftButtonUp += ObjectTypeMouseLeftButtonUp;
            SetContextMenu(objectType);
        }
示例#2
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);
        }
示例#3
0
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            ItemDragEventArgs rawObject       = args.Data.GetData(args.Data.GetFormats()[0]) as ItemDragEventArgs;
            object            droppedItem     = (rawObject.Data as System.Collections.ObjectModel.SelectionCollection).First().Item;
            LogicalInstance   logicalInstance = null;
            Type type             = null;
            bool shouldCreateItem = false;

            if (droppedItem is Type)
            {
                type = droppedItem as Type;
                if (CanAddItem(null, type))
                {
                    logicalInstance = new LogicalInstance
                    {
                        Name = "anonymous " + (Activator.CreateInstance(type) as ObjectType).TypeName,
                        Type = type.FullName
                    };
                    InstancesManager.Instance.InstancesContext.LogicalInstances.Add(logicalInstance);
                    shouldCreateItem = true;
                }
            }
            else if (droppedItem is GraphicInstance)
            {
                logicalInstance  = (droppedItem as GraphicInstance).LogicalInstance;
                type             = TypesManager.Instance.GetType(logicalInstance.Type);
                shouldCreateItem = true;
            }
            if (shouldCreateItem)
            {
                CreateItem(args, type, logicalInstance);
            }
        }
示例#4
0
        private void DeleteGraphicInstance(GraphicInstance graphicInstance)
        {
            LogicalInstance logicalInstance = graphicInstance.LogicalInstance;

            InstancesContext.GraphicInstances.Remove(graphicInstance);
            if (!graphicInstance.LogicalInstance.GraphicInstances.Any())
            {
                InstancesContext.LogicalInstances.Remove(logicalInstance);
            }
        }
示例#5
0
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            GraphicInstance  graphicInstance  = item as GraphicInstance;
            ContentPresenter contentPresenter = element as ContentPresenter;
            LogicalInstance  logicalInstance  = graphicInstance.LogicalInstance;

            if (logicalInstance != null)
            {
                contentPresenter.ContentTemplate = Create(TypesManager.Instance.GetType(logicalInstance.Type));
            }
            contentPresenter.Loaded += new RoutedEventHandler(ContentPresenterLoaded);
        }
示例#6
0
        private void CreateItem(DragEventArgs args, Type type, LogicalInstance logicalInstance)
        {
            GraphicInstance graphicInstance = null;

            if (InstancesManager.Instance.CanvasRootElement == null)
            {
                graphicInstance = new RootInstance {
                    LogicalInstance = logicalInstance
                };
            }
            else
            {
                graphicInstance = CreateGraphicVisualizedInstance(type, logicalInstance, args);
            }
            InstancesManager.Instance.InstancesContext.GraphicInstances.Add(graphicInstance);
            InstancesManager.Instance.AddInstance(graphicInstance);
            InstancesManager.Instance.InstancesContext.SubmitChanges();
        }
示例#7
0
        public void InitProperties(LogicalInstance logicalInstance)
        {
            Type type   = GetType(logicalInstance.Type);
            var  fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);

            foreach (var field in fields.Where(item => item.FieldType == typeof(DependencyProperty)))
            {
                string propertyName = field.Name.Substring(0, field.Name.LastIndexOf("Property"));
                int    count        = logicalInstance.InstanceProperties.Count(property => property.Name == propertyName);
                if (count == 0)
                {
                    InstanceProperty instanceProperty = new InstanceProperty
                    {
                        Name            = propertyName,
                        LogicalInstance = logicalInstance
                    };
                    logicalInstance.InstanceProperties.Add(instanceProperty);
                }
            }
        }
示例#8
0
        protected override void OnDropOverride(Microsoft.Windows.DragEventArgs args)
        {
            ItemDragEventArgs rawObject = args.Data.GetData(args.Data.GetFormats()[0]) as ItemDragEventArgs;
            Type type = (rawObject.Data as System.Collections.ObjectModel.SelectionCollection).First().Item as Type;

            if (CanAddItem(null, type))
            {
                LogicalInstance logicalInstance = new LogicalInstance
                {
                    Name = "anonymous " + (Activator.CreateInstance(type) as ObjectType).TypeName,
                    Type = type.FullName
                };
                InstancesManager.Instance.InstancesContext.LogicalInstances.Add(logicalInstance);
                GraphicInstance graphicInstance = new RootInstance {
                    LogicalInstance = logicalInstance
                };
                InstancesManager.Instance.InstancesContext.GraphicInstances.Add(graphicInstance);
                InstancesManager.Instance.AddInstance(graphicInstance);
                InstancesManager.Instance.InstancesContext.SubmitChanges();
            }
        }
示例#9
0
        private static void SetPropertyBindings(LogicalInstance logicalInstance, ObjectType objectType)
        {
            Type type   = objectType.GetType();
            var  fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);

            foreach (var field in fields)
            {
                if (field.FieldType == typeof(DependencyProperty))
                {
                    string           propertyName     = field.Name.Substring(0, field.Name.LastIndexOf("Property"));
                    InstanceProperty instanceProperty = logicalInstance.InstanceProperties.Single(item => item.Name == propertyName);
                    Binding          binding          = new Binding
                    {
                        Path   = new PropertyPath("Value"),
                        Mode   = BindingMode.TwoWay,
                        Source = instanceProperty
                    };
                    DependencyProperty dependencyProperty = field.GetValue(objectType) as DependencyProperty;
                    objectType.SetBinding(dependencyProperty, binding);
                }
            }
        }