Exemplo n.º 1
0
        void mnuDelete_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedSpaceObject != null)
            {
                RemoveSpaceObjectEvents(SelectedSpaceObject);
                if (canvas.Children.Contains(SelectedSpaceObject))
                {
                    canvas.Children.Remove(SelectedSpaceObject);
                }

                UnmappableObject obj = SelectedSpaceObject as UnmappableObject;
                if (obj == null)
                {
                    SpaceObject sp = SelectedSpaceObject as SpaceObject;
                    if (sp != null)
                    {
                        obj = sp.Tag as UnmappableObject;
                    }
                }
                if (obj != null)
                {
                    if (CommandsAndConditions.Contains(obj))
                    {
                        CommandsAndConditions.Remove(obj);
                    }
                }
                SelectedSpaceObject = null;
            }
        }
        static void OnCommandNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            UnmappableObject me = sender as UnmappableObject;

            if (me != null)
            {
                me.Attributes = new ObservableCollection <PropertyItem>();
                foreach (PropertyItem item in PropertyItem.GetCommandProperties(me.CommandName, (SpaceObjectType)0))
                {
                    me.Attributes.Add(item);
                }
            }
        }
Exemplo n.º 3
0
        private void canvas_Drop(object sender, DragEventArgs e)
        {
            SpaceObject so = null;

            if (e.Data.GetDataPresent(typeof(SpaceObject)))
            {
                so = e.Data.GetData(typeof(SpaceObject)) as SpaceObject;
            }
            else if (e.Data.GetDataPresent(typeof(BorderAdorner)))
            {
                so = SelectedSpaceObject as SpaceObject;
            }
            else if (e.Data.GetDataPresent(typeof(GroupBox)))
            {
                GroupBox obj = e.Data.GetData(typeof(GroupBox)) as GroupBox;
                if (obj != null)
                {
                    UnmappableObject newObj = new UnmappableObject();
                    newObj.CommandName = obj.Tag as string;

                    AddSpaceObjectEvents(newObj);
                    //Need only to add delete support at this point.
                    CommandsAndConditions.Add(newObj);
                }
            }

            if (so != null)
            {
                FrameworkElement dscope  = DragHelper.GetDragScope(so);
                DragAdorner      adorner = null;
                if (dscope != null)
                {
                    adorner = DragHelper.GetDragAdorner(dscope);
                }
                bool DoAdd = false;

                if (so.Tag == null)
                {
                    SpaceObject so2 = new SpaceObject();
                    so2.ObjectType = so.ObjectType;
                    so2.Tag        = "xxx";
                    SetSpaceObjectSize(so2);
                    AddSpaceObjectEvents(so2);
                    //so2.ObjectName = "test";
                    so = so2;
                    //so.X = Canvas.GetLeft(so);
                    //so.Z = Canvas.GetTop(so);
                    //Raise added (needs to get to Xml))

                    DoAdd = true;
                }


                if (!canvas.Children.Contains(so))
                {
                    canvas.Children.Add(so);
                }
                //Point wrkP = DragHelper.GetRelativeMousePoint(so); no
                Point wrkP = e.GetPosition(canvas);
                if (adorner != null)
                {
                    //wrkP = new Point(
                    //    adorner.LeftOffset - (ItemPool.ActualWidth + gridSplit.ActualWidth) + canvasScroll.HorizontalOffset,
                    //    adorner.TopOffset + canvasScroll.VerticalOffset);


                    wrkP = new Point(
                        adorner.LeftOffset + canvasScroll.HorizontalOffset,
                        adorner.TopOffset + canvasScroll.VerticalOffset);
                }



                so.X = wrkP.X / zoomFactor;
                so.Z = wrkP.Y / zoomFactor;


                Canvas.SetTop(so, wrkP.Y);
                Canvas.SetLeft(so, wrkP.X);

                if (DoAdd)
                {
                    this.RaiseEvent(new RoutedEventArgs(ObjectAddedEvent, so));
                }
                else
                {
                    this.RaiseEvent(new RoutedEventArgs(ObjectMovedEvent, so));
                }
                //this.Dispatcher.BeginInvoke(new Action<SpaceObject>(SetSpaceObjectSize), System.Windows.Threading.DispatcherPriority.Loaded, so);
            }
        }
Exemplo n.º 4
0
        void SpaceObject_LocationChanged(object sender, EventArgs e)
        {
            SpaceObject so = sender as SpaceObject;

            if (so != null)
            {
                if (!double.IsNaN(so.X) && !double.IsNaN(so.Z))
                {
                    double           wrkX         = so.X * zoomFactor;
                    double           wrkY         = so.Z * zoomFactor;
                    UnmappableObject removeObject = null;
                    foreach (UnmappableObject ob in CommandsAndConditions)
                    {
                        if (ob.MappableObject == so)
                        {
                            removeObject = ob;
                            break;
                        }
                    }
                    if (removeObject != null)
                    {
                        CommandsAndConditions.Remove(removeObject);
                    }
                    if (so.Parent != null)
                    {
                        ContentControl parnt = so.Parent as ContentControl;
                        if (parnt != null)
                        {
                            parnt.Content = null;
                        }
                    }
                    if (!canvas.Children.Contains(so))
                    {
                        canvas.Children.Add(so);
                    }
                    Canvas.SetTop(so, wrkY + canvasScroll.VerticalOffset);
                    Canvas.SetLeft(so, wrkX + canvasScroll.HorizontalOffset);
                }
                else
                {
                    //drop into unmappable canvas, if not already there.
                    if (canvas.Children.Contains(so))
                    {
                        canvas.Children.Remove(so);
                    }
                    UnmappableObject removeObject = null;
                    foreach (UnmappableObject ob in CommandsAndConditions)
                    {
                        if (ob.MappableObject == so)
                        {
                            removeObject = ob;
                            break;
                        }
                    }
                    if (removeObject == null)
                    {
                        removeObject                = new UnmappableObject();
                        removeObject.CommandName    = "create";
                        removeObject.Attributes     = so.Attributes;
                        removeObject.MappableObject = so;
                        so.Tag = removeObject;
                        //SelectedSpaceObject = removeObject;
                        CommandsAndConditions.Add(removeObject);
                    }
                }
            }
        }