Exemplo n.º 1
0
 public Selection(CanvasModel m, MainWindow v)
 {
     model        = m;
     view         = v;
     dragging     = false;
     currentShape = null;
 }
Exemplo n.º 2
0
 private void mitem_FileClose_Click(object sender, RoutedEventArgs e)
 {
     canvasModel       = new CanvasModel();
     canvas.Background = null;
     RefreshCanvas();
     RefreshTable();
 }
Exemplo n.º 3
0
 public DrawPolygon(CanvasModel m, MainWindow v)
 {
     model    = m;
     view     = v;
     points   = new List <Point>();
     dragging = false;
 }
Exemplo n.º 4
0
        public static void SaveToFile(string fileName, string imageFileName, CanvasModel model)
        {
            string[] content = new string[model.Shapes.Count + 1];
            content[0] = imageFileName;
            int count = 1;

            foreach (Shape s in model.Shapes.Keys)
            {
                if (s is Ellipse)
                {
                    Ellipse el = (Ellipse)s;
                    content[count] = "0;" + model.Shapes[s].X + ";" + model.Shapes[s].Y + ";" + el.Width + ";" + el.Height;
                }
                else if (s is Rectangle)
                {
                    Rectangle rec = (Rectangle)s;
                    content[count] = "1;" + model.Shapes[s].X + ";" + model.Shapes[s].Y + ";" + rec.Width + ";" + rec.Height;
                }
                else if (s is Polygon)
                {
                    Polygon pol = (Polygon)s;
                    content[count] += "2;" + model.Shapes[s].X + ";" + model.Shapes[s].Y + ";";
                    foreach (Point p in pol.Points)
                    {
                        content[count] += p.X + ";" + p.Y + ";";
                    }
                }
                count++;
            }
            File.WriteAllLines(fileName, content);
        }
Exemplo n.º 5
0
 public MainWindow()
 {
     InitializeComponent();
     canvasModel = new CanvasModel();
     currentMode = new Selection(canvasModel, this);
     tableData   = new ObservableCollection <TableRow>();
     Selected    = null;
 }
Exemplo n.º 6
0
        public static CanvasModel ReadFromFile(string fileName)
        {
            CanvasModel model = new CanvasModel();

            string[] content = File.ReadAllLines(fileName);
            model.CurrentImagePath = content[0];
            try
            {
                model.LoadImage(new BitmapImage(new Uri(content[0])));
            }
            catch (FileNotFoundException e)
            {
                throw new BindedImageFileNotFoundException(content[0]);
            }

            for (int i = 1; i < content.Length; i++)
            {
                string[] tempArr = content[i].Split(';');
                Shape    s       = null;
                Point    p       = new Point();

                if (tempArr[0] == "0")
                {
                    s        = new Ellipse();
                    p        = new Point(double.Parse(tempArr[1]), double.Parse(tempArr[2]));
                    s.Width  = double.Parse(tempArr[3]);
                    s.Height = double.Parse(tempArr[4]);
                }
                else if (tempArr[0] == "1")
                {
                    s        = new Rectangle();
                    p        = new Point(double.Parse(tempArr[1]), double.Parse(tempArr[2]));
                    s.Width  = double.Parse(tempArr[3]);
                    s.Height = double.Parse(tempArr[4]);
                }
                else if (tempArr[0] == "2")
                {
                    s = new Polygon();
                    Polygon pol = (Polygon)s;
                    p = new Point(double.Parse(tempArr[1]), double.Parse(tempArr[2]));

                    for (int j = 3; j < tempArr.Length; j += 2)
                    {
                        if (!string.IsNullOrEmpty(tempArr[j]))
                        {
                            pol.Points.Add(new Point(double.Parse(tempArr[j]), double.Parse(tempArr[j + 1])));
                        }
                    }
                }

                if (s != null)
                {
                    model.AddShape(s, p);
                }
            }
            return(model);
        }
Exemplo n.º 7
0
        private void mitem_FileOpen_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog()
            {
                DefaultExt = ".jpg",
                Filter     = "ShapeSelector shape template file (*.shps)|*.shps|JPEG Files (*.jpg, *.jpeg)|*.jpg;*.jpeg|PNG Files (*.png)|*.png|GIF Files (*.gif)|*.gif"
            };

            bool?result = dialog.ShowDialog();

            if (result == true)
            {
                string fileName = dialog.FileName;
                string ext      = dialog.FileName.Substring(dialog.FileName.Length - 5);

                if (ext == ".shps")
                {
                    try
                    {
                        canvasModel   = FileManager.ReadFromFile(fileName);
                        canvas.Width  = canvasModel.CurrentImage.Width;
                        canvas.Height = canvasModel.CurrentImage.Height;
                        currentMode.UpdateModel(canvasModel);
                    }
                    catch (BindedImageFileNotFoundException ex)
                    {
                        MessageBox.Show("Nie odnaleziono powiązanego pliku z obrazem: " + ex.FileName,
                                        "Nie znaleziono obrazu",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        return;
                    }
                }
                else
                {
                    var img = new BitmapImage(new Uri(dialog.FileName));
                    canvasModel.CurrentImagePath = dialog.FileName;
                    canvasModel.LoadImage(img);
                    canvasModel.ClearShapes();
                    canvas.Width  = img.Width;
                    canvas.Height = img.Height;
                }

                RefreshCanvas();
                RefreshTable();
            }
        }
Exemplo n.º 8
0
 public void UpdateModel(CanvasModel model)
 {
     this.model = model;
 }
Exemplo n.º 9
0
 public DrawRectangle(CanvasModel m, MainWindow v)
 {
     model    = m;
     view     = v;
     dragging = false;
 }
Exemplo n.º 10
0
 public DrawEllipse(CanvasModel m, MainWindow v)
 {
     model    = m;
     view     = v;
     dragging = false;
 }