Exemple #1
0
        private void DeleteLandmarkCommandBindind_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            for (int i = Goal.Children.Count - 1; i >= 0; i--)
            {
                Rectangle rr = Goal.Children[i] as Rectangle;
                if (rr != null)
                {
                    if (rr.Stroke == Brushes.Red)
                    {
                        Goal.Children.Remove(rr);
                        break;
                    }
                }
            }

            for (int i = Goal.Children.Count - 1; i >= 0; i--)
            {
                LandmarkView rr = Goal.Children[i] as LandmarkView;
                if (rr != null)
                {
                    if (rr.LandmarkId.Equals(SelectedLandmark))
                    {
                        Goal.Children.Remove(rr);
                        map.PlacedLandmarks.Remove(map.GetLandmark(SelectedLandmark));
                        SelectedLandmark = null;
                        break;
                    }
                }
            }
        }
Exemple #2
0
        public void startDrag(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (SelectedLandmark != null)
            {
                //DataObj mi je Landmark,
                //Prvi arg je landmarkView
                //treba da nadjem odg landmarkview, enkapsuliram ga
                //i to je to.
                //nalazim odg lview

                DataObject   capsule = new DataObject("landmark", map.GetLandmark(SelectedLandmark));
                LandmarkView lw      = null;
                foreach (var v in Goal.Children)
                {
                    lw = v as LandmarkView;
                    if (lw != null)
                    {
                        if (lw.LandmarkId.Equals(SelectedLandmark))
                        {
                            break;
                        }
                    }
                }

                mapDragAddHandlers = true;
                DragDrop.DoDragDrop(lw, capsule, DragDropEffects.Move);
            }
        }
Exemple #3
0
        public MapWindow(User u)
        {
            InitializeComponent();
            currentUser = u;
            map         = u.getUserMap();
            map.mw      = this;
            if (map.PlacedLandmarks.Count > 0)
            {
                foreach (Landmark l in map.PlacedLandmarks)
                {
                    Landmark ll = new Landmark(l.ID, l.Name, l.Description, l.Type, l.Tags,
                                               l.Climate, l.TStatus, l.Revenue, l.DoD, l.imagePath, l.EE, l.HAB, l.URB, l.position);
                    LandmarkView sp = new LandmarkView(l.ID, l.position, l.imagePath);
                    sp.Background = Brushes.White;
                    Rectangle r = new Rectangle();
                    r.Width           = 50;
                    r.Height          = 50;
                    r.Stroke          = Brushes.Black;
                    r.StrokeThickness = 1;
                    ImageBrush ib = new ImageBrush();
                    try
                    {
                        ib.ImageSource = new BitmapImage(new Uri(l.imagePath, UriKind.RelativeOrAbsolute));
                    }
                    catch (Exception e)
                    {
                        ib.ImageSource = new BitmapImage(new Uri(@"./../../Images/missing_pic.jpg", UriKind.Relative));
                    }
                    finally
                    {
                        r.Fill                  = ib;
                        sp.Width                = 54;
                        sp.Height               = 54;
                        sp.MouseLeftButtonUp   += map.doRightClick;
                        sp.MouseLeftButtonDown += startDrag;
                        r.MouseLeftButtonUp    += map.doRightClick;
                        r.MouseLeftButtonDown  += startDrag;
                        Goal.Children.Add(sp);
                        Goal.Children.Add(r);
                        tempLandmarks.Add(l);
                        Canvas.SetLeft(sp, l.position.X - 2 /*+ (tbt.Width/2)*/);
                        Canvas.SetTop(sp, l.position.Y - 2 /*+ (tbt.Height/2)*/);
                        Canvas.SetLeft(r, sp.Position.X);
                        Canvas.SetTop(r, sp.Position.Y);
                    }
                }
            }

            notSaved = false;
        }
Exemple #4
0
        private void CutLandmarkCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //cut prvo brise iz postavljenih, zatim kopira kopiju sa canvasa i brise je sa canvasa, zaj sa rect
            if (SelectedLandmark != null)
            {
                //brise iz postavlj
                foreach (var v in map.PlacedLandmarks)
                {
                    if (SelectedLandmark.Equals(v.ID))
                    {
                        map.PlacedLandmarks.Remove(v);
                        break;
                    }
                }

                //kopira sa canvasa i brise view
                for (int i = Goal.Children.Count - 1; i >= 0; i--)
                {
                    LandmarkView lv = Goal.Children[i] as LandmarkView;
                    if (lv != null)
                    {
                        if (lv.LandmarkId.Equals(SelectedLandmark))
                        {
                            clipboard = lv;
                            Goal.Children.RemoveAt(i);
                            break;
                        }
                    }
                }

                //brise i rect
                for (int i = Goal.Children.Count - 1; i >= 0; i--)
                {
                    Rectangle r = Goal.Children[i] as Rectangle;
                    if (r != null)
                    {
                        double x = Canvas.GetLeft(r);
                        double y = Canvas.GetTop(r);
                        if (x == clipboard.Position.X && y == clipboard.Position.Y)
                        {
                            Goal.Children.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
        }
Exemple #5
0
 private void CopyLandmarkCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     //copy prvo mora da pronadje land na mapi i zatim ga sacuva u clipboard
     if (SelectedLandmark != null)
     {
         for (int i = Goal.Children.Count - 1; i >= 0; i--)
         {
             LandmarkView lw = Goal.Children[i] as LandmarkView;
             if (lw != null)
             {
                 if (lw.LandmarkId.Equals(SelectedLandmark))
                 {
                     clipboard = lw;
                     //Goal.Children.RemoveAt(i);
                     break;
                 }
             }
         }
     }
 }
        private void Delete_OnClick(object sender, RoutedEventArgs e)
        {
            Landmark l = (Landmark)dgrLandmarks.SelectedItem;

            if (l == null)
            {
                MessageBox.Show("Please select one of the landmarks.", "Selection Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                AvailableLandmarks.Remove(l);
                AllLandmarks.Remove(l);

                foreach (var v in ancestor.tempLandmarks)
                {
                    if (v.ID.Equals(l.ID))
                    {
                        ancestor.tempLandmarks.Remove(v);

                        foreach (var w in ancestor.Goal.Children)
                        {
                            LandmarkView lw = w as LandmarkView;
                            if (lw != null)
                            {
                                if (lw.LandmarkId.Equals(l.ID))
                                {
                                    ancestor.Goal.Children.Remove(lw);
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }

                notSaved = true;
            }
        }
Exemple #7
0
        private void Goal_Drop(object sender, DragEventArgs e)
        {
            ToolBarTray tbt      = e.Data.GetData("toolBarTray") as ToolBarTray;
            Point       blockPos = e.GetPosition(Goal);

            if (tbt == null)
            {
                Landmark l = e.Data.GetData("landmark") as Landmark;
                l.position = blockPos;
                LandmarkView sp = new LandmarkView(l.ID, blockPos, l.imagePath);
                sp.Background = Brushes.White;
                Rectangle r = new Rectangle();
                r.Width           = 50;
                r.Height          = 50;
                r.Stroke          = Brushes.Black;
                r.StrokeThickness = 1;
                ImageBrush ib = new ImageBrush();

                try
                {
                    ib.ImageSource = new BitmapImage(new Uri(l.imagePath, UriKind.RelativeOrAbsolute));
                }
                catch (Exception ee)
                {
                    ib.ImageSource = new BitmapImage(new Uri(@"./../../Images/missing_pic.jpg", UriKind.Relative));
                }
                finally
                {
                    r.Fill    = ib;
                    sp.Width  = 54;
                    sp.Height = 54;
                    Point foundPos = new Point(-100, -100);

                    foreach (var v in Goal.Children)
                    {
                        var w = v as LandmarkView;
                        if (w != null)
                        {
                            if (w.LandmarkId.Equals(sp.LandmarkId))
                            {
                                Goal.Children.Remove(w);
                                foundPos = new Point(w.Position.X, w.Position.Y);
                                break;
                            }
                        }
                    }

                    if (foundPos != null)
                    {
                        foreach (var v in Goal.Children)
                        {
                            var w = v as Rectangle;
                            if (w != null)
                            {
                                double x = Canvas.GetLeft(w);
                                double y = Canvas.GetTop(w);
                                if (x == foundPos.X && y == foundPos.Y)
                                {
                                    Goal.Children.Remove(w);
                                    break;
                                }
                            }
                        }
                    }

                    if (mapDragAddHandlers)
                    {
                        sp.MouseLeftButtonUp   += map.doRightClick;
                        sp.MouseLeftButtonDown += startDrag;
                        r.MouseLeftButtonUp    += map.doRightClick;
                        r.MouseLeftButtonDown  += startDrag;
                    }

                    Goal.Children.Add(sp);
                    Goal.Children.Add(r);
                    Canvas.SetLeft(sp, blockPos.X - 2 /*+ (tbt.Width/2)*/);
                    Canvas.SetTop(sp, blockPos.Y - 2 /*+ (tbt.Height/2)*/);
                    Canvas.SetLeft(r, blockPos.X);
                    Canvas.SetTop(r, blockPos.Y);

                    /* map.addLandmarkView(sp/*, tempLandmarks);*/

                    if (!mapDragAddHandlers)
                    {
                        foreach (var v in tempLandmarks)
                        {
                            //landmark je postavljen
                            if (l.ID.Equals(v.ID))
                            {
                                tempLandmarks.Remove(v);
                                break;
                            }
                        }

                        tempLandmarks.Add(l);
                        LandmarkListWindow.notSaved = true;
                    }
                    else
                    {
                        foreach (var v in map.PlacedLandmarks)
                        {
                            //landmark je postavljen
                            if (l.ID.Equals(v.ID))
                            {
                                map.PlacedLandmarks.Remove(v);
                                break;
                            }
                        }

                        SelectedLandmark   = null;
                        mapDragAddHandlers = false;
                        map.PlacedLandmarks.Add(l);
                        notSaved = true;
                    }
                }
                return;
            }

            Canvas.SetLeft(tbt, blockPos.X /*+ (tbt.Width/2)*/);
            Canvas.SetTop(tbt, blockPos.Y /*+ (tbt.Height/2)*/);
            unlocked = false;
        }
Exemple #8
0
        private void PasteLandmarkCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //paste mora prvo da obrise postavljen landmark
            //zatim da postavi novi na novu poziciju
            //zajedno sa rectangle
            if (clipboard != null)
            {
                //brise postojeci iz spiska
                foreach (var v in map.PlacedLandmarks)
                {
                    if (clipboard.LandmarkId.Equals(v.ID))
                    {
                        map.PlacedLandmarks.Remove(v);
                        break;
                    }
                }

                //brise sa mape lw
                for (int i = Goal.Children.Count - 1; i >= 0; i--)
                {
                    LandmarkView lv = Goal.Children[i] as LandmarkView;
                    if (lv != null)
                    {
                        if (lv.LandmarkId.Equals(clipboard.LandmarkId))
                        {
                            Goal.Children.RemoveAt(i);
                            break;
                        }
                    }
                }

                //brise sa mape rect
                for (int i = Goal.Children.Count - 1; i >= 0; i--)
                {
                    Rectangle rr = Goal.Children[i] as Rectangle;
                    if (rr != null)
                    {
                        double x = Canvas.GetLeft(rr);
                        double y = Canvas.GetTop(rr);
                        if (x == clipboard.Position.X && y == clipboard.Position.Y)
                        {
                            Goal.Children.RemoveAt(i);
                            break;
                        }
                    }
                }

                //Dodaje kopiju
                Rectangle r = new Rectangle();
                r.Width           = 50;
                r.Height          = 50;
                r.Stroke          = Brushes.Black;
                r.StrokeThickness = 1;
                ImageBrush ib = new ImageBrush();
                try
                {
                    ib.ImageSource = new BitmapImage(new Uri(clipboard.ImagePath, UriKind.RelativeOrAbsolute));
                }
                catch (Exception ee)
                {
                    ib.ImageSource = new BitmapImage(new Uri(@"./../../Images/missing_pic.jpg", UriKind.Relative));
                }
                finally
                {
                    r.Fill               = ib;
                    clipboard.Position   = cursPos;
                    clipboard.Background = Brushes.White;
                    Goal.Children.Add(clipboard);
                    Goal.Children.Add(r);
                    clipboard.MouseLeftButtonUp   += map.doRightClick;
                    clipboard.MouseLeftButtonDown += startDrag;
                    r.MouseLeftButtonUp           += map.doRightClick;
                    r.MouseLeftButtonDown         += startDrag;
                    Canvas.SetLeft(clipboard, cursPos.X - 2 /*+ (tbt.Width/2)*/);
                    Canvas.SetTop(clipboard, cursPos.Y - 2 /*+ (tbt.Height/2)*/);
                    Canvas.SetLeft(r, cursPos.X);
                    Canvas.SetTop(r, cursPos.Y);
                    SelectedLandmark = null;
                }
            }
        }
        public bool AddALandmark(Landmark l)
        {
            Search.Text = "";
            bool found = false;

            if (copy == null)
            {
                foreach (var tt in AvailableLandmarks)
                {
                    if (tt.Equals(l))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    AvailableLandmarks.Add(l);
                    AllLandmarks.Add(l);
                    return(true);
                }

                return(false);
            }

            if (!copy.Equals(l))
            {
                AvailableLandmarks.Remove(copy);
                AvailableLandmarks.Add(l);
            }

            bool Exists = false;

            for (int i = 0; i < ancestor.tempLandmarks.Count; i++)//each (var v in ancestor.tempLandmarks)
            {
                var v = ancestor.tempLandmarks[i];
                if (v.ID.Equals(copy.ID))
                {
                    ancestor.tempLandmarks.Remove(v);
                    Exists = true;
                    for (int j = 0; j < ancestor.Goal.Children.Count; j++)//(var w in ancestor.Goal.Children)
                    {
                        LandmarkView vv = ancestor.Goal.Children[j] as LandmarkView;
                        if (vv != null)
                        {
                            if (vv.LandmarkId.Equals(copy.ID))
                            {
                                ancestor.Goal.Children.Remove(vv);
                                ancestor.removeRectangle(vv.Position);

                                LandmarkView sp = new LandmarkView(l.ID, l.position, l.imagePath);
                                sp.Background = Brushes.White;
                                Rectangle r = new Rectangle();
                                r.Width           = 50;
                                r.Height          = 50;
                                r.Stroke          = Brushes.Black;
                                r.StrokeThickness = 1;
                                ImageBrush ib = new ImageBrush();
                                ib.ImageSource = new BitmapImage(new Uri(l.imagePath, UriKind.RelativeOrAbsolute));
                                r.Fill         = ib;
                                sp.Width       = 54;
                                sp.Height      = 54;
                                ancestor.Goal.Children.Add(sp);
                                ancestor.Goal.Children.Add(r);
                                //sp.MouseLeftButtonUp += ancestor.map.doRightClick;
                                //r.MouseLeftButtonUp += ancestor.map.doRightClick;
                                Canvas.SetLeft(sp, sp.Position.X - 2 /*+ (tbt.Width/2)*/);
                                Canvas.SetTop(sp, sp.Position.Y - 2 /*+ (tbt.Height/2)*/);
                                Canvas.SetLeft(r, sp.Position.X);
                                Canvas.SetTop(r, sp.Position.Y);
                                break;
                            }
                        }
                    }
                    break;
                }
            }

            if (Exists)
            {
                ancestor.tempLandmarks.Add(l);
            }

            return(true);
        }
        public void doRightClick(object sender, MouseButtonEventArgs e)
        {
            foreach (var q in mw.Goal.Children)
            {
                LandmarkView qq = q as LandmarkView;
                if (qq != null)
                {
                    if (qq.LandmarkId.Equals(mw.SelectedLandmark))
                    {
                        mw.SelectedLandmark = null;
                        qq.Background       = Brushes.White;
                    }
                }
                else
                {
                    Rectangle rr = q as Rectangle;
                    if (rr != null)
                    {
                        if (rr.Stroke == Brushes.Red)
                        {
                            rr.Stroke = Brushes.Black;
                        }
                    }
                }
            }


            LandmarkView lw = sender as LandmarkView;

            if (lw != null)         //selektovan je landmarkview
            {
                lw.Background       = Brushes.Green;
                mw.SelectedLandmark = lw.LandmarkId;
                foreach (var v in mw.Goal.Children)
                {
                    Rectangle w = v as Rectangle;
                    if (w != null)
                    {
                        double x = Canvas.GetLeft(w);
                        double y = Canvas.GetTop(w);
                        if (lw.Position.X == x && lw.Position.Y == y)
                        {
                            w.Stroke = Brushes.Red;
                            break;
                        }
                    }
                }
            }               //selektovan je rectangle
            else
            {
                Rectangle w = sender as Rectangle;
                w.Stroke = Brushes.Red;
                foreach (var v in mw.Goal.Children)
                {
                    LandmarkView vv = v as LandmarkView;
                    if (vv != null)
                    {
                        double x = Canvas.GetLeft(w);
                        double y = Canvas.GetTop(w);
                        if (vv.Position.X == x && vv.Position.Y == y)
                        {
                            vv.Background       = Brushes.Green;
                            mw.SelectedLandmark = vv.LandmarkId;
                            break;
                        }
                    }
                }
            }
        }
        //metoda koja postavlja landmarkove na mapu
        public void setPlacedLandmarks()
        {
            for (int i = mw.Goal.Children.Count - 1; i >= 0; i--)
            {
                LandmarkView lw = mw.Goal.Children[i] as LandmarkView;

                if (lw != null)
                {
                    mw.Goal.Children.RemoveAt(i);
                }
            }


            for (int i = mw.Goal.Children.Count - 1; i >= 0; i--)
            {
                Rectangle r = mw.Goal.Children[i] as Rectangle;
                if (r != null)
                {
                    mw.Goal.Children.RemoveAt(i);
                }
            }

            foreach (var l in PlacedLandmarks)
            {
                LandmarkView lw = new LandmarkView(l.ID, l.position, l.imagePath);
                lw.Background = Brushes.White;
                Rectangle r = new Rectangle();
                r.Width           = 50;
                r.Height          = 50;
                r.Stroke          = Brushes.Black;
                r.StrokeThickness = 1;
                ImageBrush ib = new ImageBrush();
                try
                {
                    ib.ImageSource = new BitmapImage(new Uri(l.imagePath, UriKind.RelativeOrAbsolute));
                }
                catch (Exception ee)
                {
                    ib.ImageSource = new BitmapImage(new Uri(@"./../../Images/missing_pic.jpg", UriKind.Relative));
                }
                finally
                {
                    r.Fill    = ib;
                    lw.Width  = 54;
                    lw.Height = 54;

                    lw.MouseLeftButtonUp   += doRightClick;
                    lw.MouseLeftButtonDown += mw.startDrag;
                    r.MouseLeftButtonUp    += doRightClick;
                    r.MouseLeftButtonDown  += mw.startDrag;
                    mw.Goal.Children.Add(lw);
                    mw.Goal.Children.Add(r);

                    Canvas.SetLeft(lw, lw.Position.X - 2 /*+ (tbt.Width/2)*/);
                    Canvas.SetTop(lw, lw.Position.Y - 2 /*+ (tbt.Height/2)*/);
                    Canvas.SetLeft(r, lw.Position.X);
                    Canvas.SetTop(r, lw.Position.Y);
                }
            }

            MapWindow.notSaved = false;
        }