Esempio n. 1
0
        public EllipseAndRectangleView(TemplateShape shape, EnumShape enumShape)
        {
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            InitializeComponent();
            Title = "Update shape";

            shapeToUpdate = shape;
            shapeToDraw   = enumShape;

            textBox = new List <TextBox>
            {
                textBoxWidth,
                textBoxHeight,
                textBoxThickness
            };
            label = new List <Label>
            {
                labelWidth,
                labelHeight
            };
            textBoxHeight.IsEnabled = false;
            textBoxWidth.IsEnabled  = false;
            labelWidth.IsEnabled    = false;
            labelHeight.IsEnabled   = false;
            fillColor.ItemsSource   = typeof(Colors).GetProperties();
            borderColor.ItemsSource = typeof(Colors).GetProperties();

            OldData();

            buttonDraw.Click += buttonDrawUpdate_Click;
        }
        public void UpdateShapeMethod(TemplateShape shape)
        {
            int index = DrawingCanvas.Children.IndexOf(shape.Shape);

            DrawingCanvas.Children.RemoveAt(index);
            DrawingCanvas.Children.Insert(index, shape.Shape);
        }
Esempio n. 3
0
        private void buttonDraw_Click(object sender, RoutedEventArgs e)
        {
            TemplateShape ret = null;

            switch (shapeToDraw)
            {
            case EnumShape.ELLIPSE:
                if (!(ValidateTexBox(textBoxWidth) && ValidateTexBox(textBoxHeight) && ValidateTexBox(textBoxThickness) && ValidateColor(borderColor) && ValidateColor(fillColor)))
                {
                    return;
                }
                ret = CreateEllipse();
                break;

            case EnumShape.RECTANGLE:
                if (!(ValidateTexBox(textBoxWidth) && ValidateTexBox(textBoxHeight) && ValidateTexBox(textBoxThickness) && ValidateColor(borderColor) && ValidateColor(fillColor)))
                {
                    return;
                }
                ret = CreateRectangle();
                break;
            }
            StackClass.NewShape = ret;
            SelectedButton(buttonDraw);
            Close();
        }
Esempio n. 4
0
        public ImageView(TemplateShape shape, EnumShape enumShape)
        {
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            InitializeComponent();
            Title = "Update image window";

            shapeToUpdate = shape;
            shapeToDraw   = enumShape;
            textBox       = new List <TextBox>
            {
                textBoxWidth,
                textBoxHeight,
            };
            buttons = new List <Button>
            {
                buttonChoose,
                buttonDraw
            };
            label = new List <Label>
            {
                labelWidth,
                labelHeight
            };
            textBoxHeight.IsEnabled = false;
            textBoxWidth.IsEnabled  = false;
            labelWidth.IsEnabled    = false;
            labelHeight.IsEnabled   = false;
            shapeToDraw             = EnumShape.IMAGE;

            OldImageData();

            buttonDraw.Click += buttonDrawUpdate_Click;
        }
 void UndoClearAction()
 {
     while (StackClass.ClearShape.Count != 0)
     {
         TemplateShape temp = StackClass.ClearShape.Pop();
         DrawingCanvas.Children.Add(temp.Draw());
         StackClass.ActiveShape.Push(temp);
     }
 }
        private void buttonRedo_Click(object sender, RoutedEventArgs e)
        {
            if (StackClass.Undo.Count == 0)
            {
                return;
            }
            TemplateShape shape = StackClass.Undo.Pop();

            DrawingCanvas.Children.Add(shape.Draw());
            StackClass.ActiveShape.Push(shape);
        }
        void DrawShapeOnCanvas()
        {
            TemplateShape templateShape = StackClass.NewShape;

            if (templateShape == null)
            {
                return;
            }
            StackClass.ActiveShape.Push(templateShape);
            DrawingCanvas.Children.Add(templateShape.Draw());
        }
        private void buttonUndo_Click(object sender, RoutedEventArgs e)
        {
            if (StackClass.ClearShape.Count != 0)
            {
                UndoClearAction();
                return;
            }
            if (StackClass.ActiveShape.Count == 0)
            {
                return;
            }
            TemplateShape shape = StackClass.ActiveShape.Pop();

            DrawingCanvas.Children.RemoveAt(DrawingCanvas.Children.Count - 1);
            StackClass.Undo.Push(shape);
        }
        public PolygonView(TemplateShape shape, EnumShape enumShape)
        {
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            InitializeComponent();
            Title = "Update polygon window";

            shapeToUpdate           = shape;
            shapeToDraw             = enumShape;
            fillColor.ItemsSource   = typeof(Colors).GetProperties();
            borderColor.ItemsSource = typeof(Colors).GetProperties();
            shapeToDraw             = EnumShape.POLYGON;

            OldPolygonData();

            buttonDraw.Click += buttonDrawUpdate_Click;
        }
        private void buttonDraw_Click(object sender, RoutedEventArgs e)
        {
            TemplateShape ret = null;

            switch (shapeToDraw)
            {
            case EnumShape.POLYGON:
                if (!(ValidateTexBox(textBoxThickness) && ValidateColor(borderColor) && ValidateColor(fillColor)))
                {
                    return;
                }
                ret = CreatePolygon();
                break;
            }
            StackClass.NewShape = ret;
            SelectedButton(buttonDraw);
            Close();
        }
Esempio n. 11
0
        private void buttonDraw_Click(object sender, RoutedEventArgs e)
        {
            TemplateShape ret = null;

            switch (shapeToDraw)
            {
            case EnumShape.IMAGE:
                if (!(ValidateTexBox(textBoxWidth) && ValidateTexBox(textBoxHeight) && ValidateImagePath()))
                {
                    return;
                }
                ret = CreateImage();
                break;
            }
            StackClass.NewShape = ret;
            SelectedButton(buttonDraw);
            Close();
        }
Esempio n. 12
0
        /// <summary>
        /// 加载用户自定义的模板
        /// </summary>
        public Task LoadTemplate()
        {
            flowLayoutPanelTemplate.Controls.Clear();
            var task = Task.Run(() =>
            {
                string path    = Application.StartupPath + "/ScadaTemplate/TemplateShapes/";
                string[] temps = Directory.GetFiles(path, "*.tpl");
                for (int i = 0; i < temps.Length; i++)
                {
                    FileStream fs = null;
                    try
                    {
                        TemplateShape shape = null;
                        fs = new FileStream(temps[i], FileMode.Open);
                        fs.Seek(0, SeekOrigin.Current);
                        IFormatter formatter = new BinaryFormatter();
                        while (fs.Position < fs.Length)
                        {
                            shape = (TemplateShape)formatter.Deserialize(fs);
                        }
                        System.Windows.Forms.Label button = new System.Windows.Forms.Label()
                        {
                            Text             = shape.Title,
                            Tag              = shape.Path,
                            Width            = 120,
                            Height           = 40,
                            BorderStyle      = BorderStyle.FixedSingle,
                            BackColor        = Color.White,
                            ForeColor        = Color.Blue,
                            Font             = new Font("微软雅黑", 13),
                            ContextMenuStrip = this.contextMenuStrip1,
                            TextAlign        = ContentAlignment.MiddleCenter,
                        };

                        button.MouseDoubleClick += Button_MouseDoubleClick;
                        button.MouseClick       += Button_MouseClick;
                        if (this.IsHandleCreated)
                        {
                            this.BeginInvoke(new Action(delegate
                            {
                                flowLayoutPanelTemplate.Controls.Add(button);
                            }));
                        }
                    }
                    catch
                    {
#if DEBUG
                        throw;
#else
#endif
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                }
            });

            return(task);
        }
Esempio n. 13
0
        private void Button_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            System.Windows.Forms.Label button = sender as System.Windows.Forms.Label;
            if (e.Clicks == 2)
            {
                button.BackColor = Color.White;
                if (this.mediator.ActiveWork != null && button.Tag != null)
                {
                    TemplateShape newShape = null;
                    FileStream    fs       = null;
                    try
                    {
                        fs = new FileStream(Application.StartupPath + "/ScadaTemplate/TemplateShapes/" + button.Tag.ToString(), FileMode.Open);
                        fs.Seek(0, SeekOrigin.Current);
                        IFormatter formatter = new BinaryFormatter();
                        while (fs.Position < fs.Length)
                        {
                            newShape = (TemplateShape)formatter.Deserialize(fs);
                        }
                    }
                    catch (Exception emx)
                    {
#if DEBUG
                        throw emx;
#else
                        MessageBox.Show(this, emx.Message);
#endif
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }

                    try
                    {
                        if (newShape == null)
                        {
                            return;
                        }
                        Point cp = new Point();

                        cp.X = ((WorkForm)this.mediator.ActiveWork).GraphControl.ClientRectangle.Width / 2 - Convert.ToInt32(newShape.TplShape.Width) / 2;
                        cp.Y = ((WorkForm)this.mediator.ActiveWork).GraphControl.ClientRectangle.Height / 2 - Convert.ToInt32(newShape.TplShape.Height) / 2;

                        ///重新获取GUID

                        GetTemplateShape(newShape.TplShape, newShape.shapes);
                        for (int i = 0; i < newShape.shapes.Count; i++)
                        {
                            //此处要做无限循环处理,读取容器内容
                            newShape.shapes[i].Site      = ((WorkForm)this.mediator.ActiveWork).GraphControl;
                            newShape.shapes[i].Layer     = ((WorkForm)this.mediator.ActiveWork).GraphControl.BasicLayer;
                            newShape.shapes[i].LayerName = ((WorkForm)this.mediator.ActiveWork).GraphControl.BasicLayer.Name;
                            newShape.shapes[i].GID       = ((WorkForm)this.mediator.ActiveWork).GraphControl.Abstract.GID;
                        }
                        newShape.TplShape.GenerateNewUID();
                        newShape.TplShape.Site      = ((WorkForm)this.mediator.ActiveWork).GraphControl;
                        newShape.TplShape.Layer     = ((WorkForm)this.mediator.ActiveWork).GraphControl.BasicLayer;
                        newShape.TplShape.LayerName = ((WorkForm)this.mediator.ActiveWork).GraphControl.BasicLayer.Name;
                        newShape.TplShape.GID       = ((WorkForm)this.mediator.ActiveWork).GraphControl.Abstract.GID;
                        ((WorkForm)this.mediator.ActiveWork).GraphControl.AddShape(newShape.TplShape, AddShapeType.Create);

                        for (int i = 0; i < newShape.shapes.Count; i++)
                        {
                            //此处要做无限循环处理,读取容器内容
                            ((WorkForm)this.mediator.ActiveWork).GraphControl.AddShape(newShape.shapes[i], AddShapeType.Create);
                        }
                        newShape.TplShape.MoveOffiset(cp.X - newShape.TplShape.X, cp.Y - newShape.TplShape.Y);
                    }
                    catch (Exception emx)
                    {
#if DEBUG
                        throw emx;
#else
                        MessageBox.Show(this, emx.Message);
#endif
                    }
                }
            }
        }