Beispiel #1
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
 {
     switch (connectionId)
     {
     case 1:
         this.MyDesigner = ((MachineCreater.DesignerCanvas)(target));
         return;
     }
     this._contentLoaded = true;
 }
Beispiel #2
0
        internal ConnectorInfo GetInfo()
        {
            ConnectorInfo info = new ConnectorInfo();

            info.DesignerItemLeft = DesignerCanvas.GetLeft(this.ParentDesignerItem);
            info.DesignerItemTop  = DesignerCanvas.GetTop(this.ParentDesignerItem);
            info.DesignerItemSize = new Size(this.ParentDesignerItem.ActualWidth, this.ParentDesignerItem.ActualHeight);
            info.Orientation      = this.Orientation;
            info.Position         = this.Position;
            return(info);
        }
Beispiel #3
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            DesignerCanvas canvas = GetDesignerCanvas(this);

            if (canvas != null)
            {
                // position relative to DesignerCanvas
                if (this.Type == CON_TYPE.OUTPUT && this.Connections.Count == 0)
                {
                    this.dragStartPoint = new Point?(e.GetPosition(canvas));
                }
                e.Handled = true;
            }
        }
Beispiel #4
0
        private void ShowAdorner()
        {
            // the ConnectionAdorner is created once for each Connection
            if (this.connectionAdorner == null)
            {
                DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas;

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
                if (adornerLayer != null)
                {
                    this.connectionAdorner = new ConnectionAdorner(designer, this);
                    adornerLayer.Add(this.connectionAdorner);
                }
            }
            this.connectionAdorner.Visibility = Visibility.Visible;
        }
Beispiel #5
0
        public ConnectionAdorner(DesignerCanvas designer, Connection connection)
            : base(designer)
        {
            this.designerCanvas = designer;
            adornerCanvas       = new Canvas();
            this.visualChildren = new VisualCollection(this);
            this.visualChildren.Add(adornerCanvas);

            this.connection = connection;
            this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged);

            InitializeDragThumbs();

            drawingPen          = new Pen(Brushes.LightSlateGray, 1);
            drawingPen.LineJoin = PenLineJoin.Round;

            base.Unloaded += new RoutedEventHandler(ConnectionAdorner_Unloaded);
        }
Beispiel #6
0
        void Connection_Unloaded(object sender, RoutedEventArgs e)
        {
            // do some housekeeping when Connection is unloaded

            // remove event handler
            this.Source = null;
            this.Sink   = null;

            // remove adorner
            if (this.connectionAdorner != null)
            {
                DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas;

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
                if (adornerLayer != null)
                {
                    adornerLayer.Remove(this.connectionAdorner);
                    this.connectionAdorner = null;
                }
            }
        }
Beispiel #7
0
 public DesignerItem(String Uid, DesignerCanvas parent)
     : this(Guid.NewGuid(), parent)
 {
     this.Uid = Uid;
     // _DesignerCanvas = parent;
     // attach_Device_list = new ObservableCollection<Device>();
     if (Uid.StartsWith("0001-01"))  //ES brewer
     {
         main_Device = new Dev_ES(parent.GetPositionID(DesignerCanvas.DeviceType.DEV_BREWER));
     }
     else if (Uid.StartsWith("0002")) //grinder
     {
         main_Device = new Dev_Grinder(parent.GetPositionID(DesignerCanvas.DeviceType.DEV_GRINDER));
     }
     else if (Uid.StartsWith("0003")) //canister
     {
         main_Device = new Dev_Canister(0x01, parent.GetPositionID(DesignerCanvas.DeviceType.DEV_CANISTER));
     }
     else if (Uid.StartsWith("0004")) //mixer
     {
         main_Device = new Dev_Mixer_L(parent.GetPositionID(DesignerCanvas.DeviceType.DEV_MIXER));
     }
     else if (Uid.StartsWith("000f-02")) //gravity
     {
         main_Device = new Dev_Boiler_G(parent.GetPositionID(DesignerCanvas.DeviceType.DEV_BOILER));
     }
     else if (Uid.StartsWith("000f-03")) //es
     {
         main_Device = new Dev_Boiler_ES(parent.GetPositionID(DesignerCanvas.DeviceType.DEV_BOILER));
     }
     else if (Uid.StartsWith("0000-02")) //waiwei
     {
         main_Device = new DEV_virMachine(parent.GetPositionID(DesignerCanvas.DeviceType.DEV_VIRMACHINE));
     }
     else if (Uid.StartsWith("000a-01")) //pump
     {
         main_Device = new DEV_Waterpump(1, 1);
     }
 }
Beispiel #8
0
 public SelectionService(DesignerCanvas canvas)
 {
     this.designerCanvas = canvas;
 }
Beispiel #9
0
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                DesignerItem newItem = null;
                Object       content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));

                DeviceType itemtype = DeviceType.DEV_Init;
                if (dragObject.UID.StartsWith("0001"))   //
                {
                    itemtype = DeviceType.DEV_BREWER;
                }
                else if (dragObject.UID.StartsWith("0002")) // this is for grinder
                {
                    itemtype = DeviceType.DEV_GRINDER;
                }
                else if (dragObject.UID.StartsWith("0003")) // this is for canister
                {
                    itemtype = DeviceType.DEV_CANISTER;
                }
                else if (dragObject.UID.StartsWith("0004")) // this is for mixer
                {
                    itemtype = DeviceType.DEV_MIXER;
                }
                else if (dragObject.UID.StartsWith("000f")) // this is for boiler
                {
                    itemtype = DeviceType.DEV_BOILER;
                }
                else if (dragObject.UID.StartsWith("0008")) // this is for machine
                {
                    itemtype = DeviceType.DEV_CUP;
                }
                else if (dragObject.UID.StartsWith("000c")) // this is for machine
                {
                    itemtype = DeviceType.DEV_LED;
                }
                else if (dragObject.UID.StartsWith("0018")) // this is for machine
                {
                    itemtype = DeviceType.DEV_DRIP;
                }
                else if (dragObject.UID.StartsWith("0019")) // this is for machine
                {
                    itemtype = DeviceType.DEV_WASTER;
                }
                else if (dragObject.UID.StartsWith("001a")) // this is for machine
                {
                    itemtype = DeviceType.DEV_DOOR;
                }
                else if (dragObject.UID.StartsWith("0000-02")) // this is for machine
                {
                    itemtype = DeviceType.DEV_VIRMACHINE;
                }
                if (!isValid(itemtype))
                {
                    MessageBox.Show("can not create more!");
                    return;
                }


                if (content != null)
                {
                    newItem = new DesignerItem(dragObject.UID, this);

                    newItem.Content = content;
                    Point position = e.GetPosition(this);

                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        DesignerCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        DesignerCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }

                    Canvas.SetZIndex(newItem, this.Children.Count);
                    this.Children.Add(newItem);

                    _machineDevicelist.Add(newItem.ID, newItem);
                    SetConnectorDecoratorTemplate(newItem);
                    Control decorator = newItem.Template.FindName("PART_ConnectorDecorator", newItem) as Control;
                    if (dragObject.UID.Equals("0000-00"))   // this is for valve
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_valve");
                        }
                    }
                    else if (dragObject.UID.StartsWith("0001")) // this is for brewer
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_brewer");
                        }
                    }
                    else if (dragObject.UID.StartsWith("0002")) // this is for grinder
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_grinder");
                        }
                    }
                    else if (dragObject.UID.StartsWith("0003")) // this is for canister
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_can");
                        }
                    }
                    else if (dragObject.UID.StartsWith("0004")) // this is for mixer
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_brewer");
                        }
                    }
                    else if (dragObject.UID.StartsWith("000f")) // this is for boiler
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_boiler");
                        }
                    }
                    else if (dragObject.UID.StartsWith("000a")) // this is for boiler
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_pump");
                        }
                    }
                    else if (dragObject.UID.StartsWith("0008"))
                    {
                        if (decorator != null)
                        {
                            decorator.SetResourceReference(Control.TemplateProperty, "ConnectorDecoratorTemplate_end");
                        }
                    }
                    //update selection
                    this.SelectionService.SelectItem(newItem);
                    newItem.Focus();
                }

                e.Handled = true;
            }
        }