//-----------------------------------------------------------------

        #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
            }
        }
示例#2
0
        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

            //--------------
        }