//Движение protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e) { base.OnMouseMove(e); if (SelectBuildObject == null) { return; } Point mousePosition = e.GetPosition(this); //With scale mousePosition = new Point((mousePosition.X / ScaleTransformForUIElement.ScaleX), (mousePosition.Y / ScaleTransformForUIElement.ScaleY)); switch (SelectTool) { #region Line case Tools.Line: if (SelectBuildObject is LineWall) { LineWall lineWall = (SelectBuildObject as LineWall); lineWall.EndPoint = new Point(Math.Abs(mousePosition.X - lineWall.FirstPoint.X) > 10 ? mousePosition.X : lineWall.FirstPoint.X, Math.Abs(mousePosition.Y - lineWall.FirstPoint.Y) > 10 ? mousePosition.Y : lineWall.FirstPoint.Y); } break; #endregion #region PolyLine case Tools.PolyLine: if (SelectBuildObject is PolyLineWall) { PolyLineWall polyLineWall = (SelectBuildObject as PolyLineWall); polyLineWall.EndPoint = new Point(Math.Abs(mousePosition.X - polyLineWall.Points[polyLineWall.Points.Count - 2].X) > 10 ? mousePosition.X : polyLineWall.Points[polyLineWall.Points.Count - 2].X, Math.Abs(mousePosition.Y - polyLineWall.Points[polyLineWall.Points.Count - 2].Y) > 10 ? mousePosition.Y : polyLineWall.Points[polyLineWall.Points.Count - 2].Y); } break; #endregion #region Cricle case Tools.Cricle: if (SelectBuildObject is EllipseWall) { EllipseGeometry ellipseGeometry = (SelectBuildObject as EllipseWall).EllipseObject; ellipseGeometry.RadiusX = Math.Sqrt(Math.Pow(ellipseGeometry.Center.Y - mousePosition.Y, 2) + Math.Pow(ellipseGeometry.Center.X - mousePosition.X, 2)); ellipseGeometry.RadiusY = ellipseGeometry.RadiusX; } break; #endregion #region Rectangle case Tools.Rectangle: if (SelectBuildObject is RectangleWall) { RectangleGeometry rectangleGeometry = (SelectBuildObject as RectangleWall).RectangleObject; rectangleGeometry.Rect = new Rect(rectangleGeometry.Rect.Location, mousePosition); } break; #endregion #region ImportImage case Tools.ImportImg: if (SelectBuildObject is RectangleWithImage) //костыль { if ((SelectBuildObject as RectangleWithImage).ImgDraw.Rect != Rect.Empty) { RectangleGeometry rectangleGeometry = (SelectBuildObject as RectangleWithImage).RectangleObject; ImageDrawing imgDraw = (SelectBuildObject as RectangleWithImage).ImgDraw; rectangleGeometry.Rect = new Rect(rectangleGeometry.Rect.Location, mousePosition); imgDraw.Rect = rectangleGeometry.Rect; } } break; #endregion #region PathEvacuation case Tools.PathEvacuacion: if (SelectBuildObject is EvacPath) { EvacPath evacPath = (SelectBuildObject as EvacPath); evacPath.EndPoint = new Point(Math.Abs(mousePosition.X - evacPath.Points[evacPath.Points.Count - 2].X) > 10 ? mousePosition.X : evacPath.Points[evacPath.Points.Count - 2].X, Math.Abs(mousePosition.Y - evacPath.Points[evacPath.Points.Count - 2].Y) > 10 ? mousePosition.Y : evacPath.Points[evacPath.Points.Count - 2].Y); } break; #endregion } }
//----------------------------------------------------------------- #region MouseEvents //Нажатие protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); Point mousePosition = e.GetPosition(this); //With scale mousePosition = new Point((mousePosition.X / ScaleTransformForUIElement.ScaleX), (mousePosition.Y / ScaleTransformForUIElement.ScaleY)); switch (SelectTool) { #region Line case Tools.Line: if (SelectBuildObject != null) { return; } SelectBuildObject = new LineWall("Стена") { ThinknessVisualObject = SettingTool.Thinckness, FirstPoint = mousePosition, EndPoint = mousePosition, }; Program.CurrentProject.ListBuildObject.Add(SelectBuildObject); this.AddBuildObject(SelectBuildObject); break; #endregion #region PolyLine case Tools.PolyLine: if (SelectBuildObject == null) { SelectBuildObject = new PolyLineWall("ЛоманаяСтена") { ThinknessVisualObject = SettingTool.Thinckness, FirstPoint = mousePosition, }; (SelectBuildObject as PolyLineWall).Points.Add(mousePosition); Program.CurrentProject.ListBuildObject.Add(SelectBuildObject); this.AddBuildObject(SelectBuildObject); } else if (SelectBuildObject is PolyLineWall) { (SelectBuildObject as PolyLineWall).Points.Add(mousePosition); } break; #endregion #region Cricle case Tools.Cricle: if (SelectBuildObject == null) { SelectBuildObject = new EllipseWall("Круговая стена") { ThinknessVisualObject = SettingTool.Thinckness }; EllipseGeometry ellipseGeometry = (SelectBuildObject as EllipseWall).EllipseObject; ellipseGeometry.Center = mousePosition; ellipseGeometry.RadiusX = SelectBuildObject.ThinknessVisualObject; ellipseGeometry.RadiusY = SelectBuildObject.ThinknessVisualObject; Program.CurrentProject.ListBuildObject.Add(SelectBuildObject); this.AddBuildObject(SelectBuildObject); } break; #endregion #region Rectangle case Tools.Rectangle: if (SelectBuildObject == null) { SelectBuildObject = new RectangleWall("Прямоугольная стена") { ThinknessVisualObject = SettingTool.Thinckness }; RectangleGeometry rectangleGeometry = (SelectBuildObject as RectangleWall).RectangleObject; rectangleGeometry.Rect = new Rect(mousePosition, mousePosition); Program.CurrentProject.ListBuildObject.Add(SelectBuildObject); this.AddBuildObject(SelectBuildObject); } break; #endregion #region ImportImage case Tools.ImportImg: if (SelectBuildObject is RectangleWithImage) { RectangleWithImage rectangleWithImage = SelectBuildObject as RectangleWithImage; rectangleWithImage.RectangleObject.Rect = new Rect(mousePosition, mousePosition); rectangleWithImage.ImgDraw.Rect = rectangleWithImage.RectangleObject.Rect; Program.CurrentProject.ListBuildObject.Add(SelectBuildObject); this.AddBuildObject(SelectBuildObject); Canvas.SetLeft(rectangleWithImage.ImportImage, mousePosition.X); Canvas.SetTop(rectangleWithImage.ImportImage, mousePosition.Y); } break; #endregion #region PathEvacuacion case Tools.PathEvacuacion: if (SelectBuildObject == null) { SelectBuildObject = new EvacPath("Путь эвакуации", "PointerEvacTool") { ThinknessVisualObject = SettingTool.Thinckness, FirstPoint = mousePosition, }; (SelectBuildObject as EvacPath).Points.Add(mousePosition); Program.CurrentProject.ListBuildObject.Add(SelectBuildObject); this.AddBuildObject(SelectBuildObject); } else if (SelectBuildObject is EvacPath) { (SelectBuildObject as EvacPath).AddPointWithPointer(mousePosition); //обновление this.RemoveBuildObject(SelectBuildObject); this.AddBuildObject(SelectBuildObject); } break; #endregion #region Exit //доработать case Tools.Exit: if (SelectBuildObject == null) { SelectBuildObject = new RectangleWithImage("Выход", "ExitManIcon"); RectangleWithImage rectWithImg = (SelectBuildObject as RectangleWithImage); double widthRect = SettingTool.Thinckness; rectWithImg.RectangleObject.Rect = new Rect(new Point(mousePosition.X - widthRect, mousePosition.Y - widthRect), new Point(mousePosition.X + widthRect, mousePosition.Y + widthRect)); rectWithImg.ImgDraw.Rect = rectWithImg.RectangleObject.Rect; Program.CurrentProject.ListBuildObject.Add(SelectBuildObject); this.AddBuildObject(SelectBuildObject); Canvas.SetLeft(rectWithImg.ImportImage, (mousePosition.X - widthRect) * ScaleTransformForUIElement.ScaleX); Canvas.SetTop(rectWithImg.ImportImage, (mousePosition.Y - widthRect) * ScaleTransformForUIElement.ScaleY); } break; #endregion } }
public void LoadFromFile(XmlTextReader xmlIn) { ListBuildObject.Clear(); //setting xmlIn xmlIn.WhitespaceHandling = WhitespaceHandling.None; xmlIn.MoveToContent(); if (xmlIn.Name != "Project") { throw new ArgumentException("Incorrect File Format."); } Name = xmlIn.GetAttribute("Name"); //цикл для чтения тегов элементов проекта #region ReadElementTag do { if (!xmlIn.Read()) { break; } if (xmlIn.NodeType == XmlNodeType.EndElement) { continue; } switch (xmlIn.Name) { case "LineWall": LineWall lineWall = new LineWall(xmlIn); ListBuildObject.Add(lineWall); break; case "PolyLineWall": PolyLineWall polyLineWall = new PolyLineWall(xmlIn); ListBuildObject.Add(polyLineWall); break; case "EvacPath": EvacPath evacPath = new EvacPath(xmlIn); ListBuildObject.Add(evacPath); break; case "EllipseWall": EllipseWall ellipseWall = new EllipseWall(xmlIn); ListBuildObject.Add(ellipseWall); break; case "RectangleWall": RectangleWall rectangleWall = new RectangleWall(xmlIn); ListBuildObject.Add(rectangleWall); break; case "RectangleWithImage": RectangleWithImage rectangleWithImage = new RectangleWithImage(xmlIn); ListBuildObject.Add(rectangleWithImage); break; } } while (!xmlIn.EOF); #endregion //-------------- }