public override void Execute(object parameter)
        {
            foreach (VisualCornerManipulator manipulator in _context.CornerManipulators)
            {
                _context.MapEntities.Remove(manipulator);
            }
            _context.CornerManipulators.Clear();

            if (_context.LastSelected is VisualPolygonalBuilding)
            {
                VisualPolygonalBuilding polygon = (VisualPolygonalBuilding)_context.LastSelected;

                for (int i = 0; i < polygon.Corners.Count; i++)
                {
                    VisualCornerManipulator manipulator = new VisualCornerManipulator(polygon.SourceEntity, polygon, i);
                    _context.CornerManipulators.Add(manipulator);
                    _context.MapEntities.Add(manipulator);
                }
                _context.CurrentlyManipulatedObject = _context.LastSelected;
            }
            else if (_context.LastSelected is WallElement)
            {
                WallElement wall = (WallElement)_context.LastSelected;
                for (int i = 0; i < 2; i++)
                {
                    VisualCornerManipulator manipulator = new VisualCornerManipulator(wall.SourceEntity, wall, i);
                    _context.CornerManipulators.Add(manipulator);
                    _context.MapEntities.Add(manipulator);
                }
                _context.CurrentlyManipulatedObject = _context.LastSelected;
            }
        }
 public VisualCornerManipulator(IMapEntity mapEntity, VisualPolygonalBuilding polygon, int index) : base(mapEntity)
 {
     Color    = Colors.Blue;
     Width    = Constants.ManipulatorDiameter;
     Height   = Constants.ManipulatorDiameter;
     _polygon = polygon;
     _polygon.PropertyChanged += manipulatedObject_PropertyChanged;
     _cornerIndex              = index;
 }
        public override void Do()
        {
            _context.SelectedEntities.Clear();

            if (Building == null)
            {
                // Create polygon points from line collection
                List <Point2D> points = new List <Point2D>();
                double         x      = 0; // sum of x coordinates
                double         y      = 0; // sum of y coordinates
                foreach (WallElement wall in ((DataModel)_context).NewPolygonalBuildingWalls)
                {
                    Point2D point1 = new Point2D()
                    {
                        X = wall.X1, Y = wall.Y1
                    };
                    Point2D point2 = new Point2D()
                    {
                        X = wall.X2, Y = wall.Y2
                    };
                    if (points.AddIfNoPointPresent(point1)) // add first point if no point is at the location
                    {
                        x += point1.X;
                        y += point1.Y;
                    }
                    if (points.AddIfNoPointPresent(point2)) // add second point if no point is at the location
                    {
                        x += point2.X;
                        y += point2.Y;
                    }
                    ((DataModel)_context).MapEntities.Remove(wall);    // remove wall from the world
                }

                x /= (points.Count);                   // calculate x coordinate of the polygon center
                y /= (points.Count);                   // calculate y coordinate of the polygon center

                for (int i = 0; i < points.Count; i++) // move corner points to local coordinate system of the polygon
                {
                    points[i] = new Point2D()
                    {
                        X = points[i].X - x, Y = points[i].Y - y
                    };
                }

                // create polygon element
                Building = new VisualPolygonalBuilding(new PolygonBuilding()
                {
                    Corners = points, X = x, Y = y, Id = ((DataModel)_context).CurrentMap.GetNewId(), Name = Constants.DefaultHouseName
                });
                Building.CreateFloorFromDimensions();
            }

            ((DataModel)(_context)).MapEntities.Add(Building);   // add polygon to the world
            Building.IsSelected = true;
        }