public void Draw(Floor f)
        {
            for (int r = 0; r < this.dimension.x; r++)
            {
                for (int c = 0; c < this.dimension.y; c++)
                {
                    Gizmos.color = Color.gray;
                    Gizmos.DrawWireCube(this.GetPos(r, c), this.boxSize);
                    Gizmos.color = Color.white;
                }
            }

            if (this.showRooms && f.Rooms != null)
            {
                foreach (Room r in f.Rooms)
                {
                    Gizmos.color = Color.red;
                    if (r is CircleRoom)
                    {
                        Gizmos.DrawWireSphere(r.Position, ((CircleRoom)r).Radius);
                    }
                    else
                    {
                        RectangleRoom rect = (RectangleRoom)r;
                        Vector3       s    = rect.Position + rect.transform.parent.InverseTransformDirection(rect.transform.up) * rect.Dimentions.y / 2f;
                        Vector3       e    = rect.Position - rect.transform.parent.InverseTransformDirection(rect.transform.up) * rect.Dimentions.y / 2f;
                        Gizmos.DrawLine(s, e);
                        Gizmos.matrix = Matrix4x4.TRS(r.Position, r.transform.localRotation, r.transform.localScale);
                        Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
                        Gizmos.matrix = Matrix4x4.identity;
                    }
                    Gizmos.color = Color.white;
                }
            }
        }
Example #2
0
        private void CanvasAreaForSchemeOfRoom_KeyUp(object sender, KeyEventArgs e)
        {
            if (_IsRoom)
            {
                if (e.Key == Key.Enter)
                {
                    if (line != null && line2 != null)
                    {
                        RectangleRoom room = new RectangleRoom
                        {
                            X1 = Convert.ToInt32(line.X1),
                            Y1 = Convert.ToInt32(line.Y1),

                            X2 = Convert.ToInt32(line.X2),
                            Y2 = Convert.ToInt32(line.Y2),

                            X3 = Convert.ToInt32(line2.X2),
                            Y3 = Convert.ToInt32(line2.Y2),

                            X4 = Convert.ToInt32(line4.X2),
                            Y4 = Convert.ToInt32(line4.Y2)
                        };
                        SingleSpaceParams.getInstance().Rooms.Add(room);
                    }

                    line    = null;
                    line2   = null;
                    line3   = null;
                    line4   = null;
                    isPaint = false;
                    pressEnterLabel.Visibility = Visibility.Collapsed;
                }

                if (e.Key == Key.Escape)
                {
                    widthRoomTextBlock.Visibility      = Visibility.Collapsed;
                    widthRoomTextBox.Visibility        = Visibility.Collapsed;
                    lengthRoomTextBlock.Visibility     = Visibility.Collapsed;
                    lengthRoomTextBox.Visibility       = Visibility.Collapsed;
                    setLengthAndWidthButton.Visibility = Visibility.Collapsed;

                    if (line != null && line2 != null && line3 != null && line4 != null)
                    {
                        CanvasAreaForSchemeOfRoom.Children.Remove(line);
                        CanvasAreaForSchemeOfRoom.Children.Remove(line2);
                        CanvasAreaForSchemeOfRoom.Children.Remove(line3);
                        CanvasAreaForSchemeOfRoom.Children.Remove(line4);
                    }
                    isPaint = false;
                }
            }
        }
 private Vector3 GetRoomEdgePoint(Room room, LayerPath p)
 {
     if (room is CircleRoom)
     {
         CircleRoom c = (CircleRoom)room;
         return(GenerationUtility.CircleLineIntersection(p.Start.Position, p.End.Position, c.Position, c.Radius));
     }
     else
     {
         Vector3       tl, tr, bl, br;
         RectangleRoom rect = (RectangleRoom)room;
         rect.BoxBounds(out tl, out tr, out bl, out br);
         return(GenerationUtility.BoxLineIntersection(p.Start.Position, p.End.Position, tl, tr, bl, br));
     }
 }
Example #4
0
        public IEnumerator RasterizeFloor(Floor f)
        {
            Square[,,,] squares = f.Squares;

            foreach (Room room in f.Rooms)
            {
                if (room is CircleRoom)
                {
                    CircleRoom circle = (CircleRoom)room;
                    RasterizeCircle(squares, f.rasterizationGrid, circle.Position, circle.Radius);
                }
                else
                {
                    RectangleRoom rect = (RectangleRoom)room;
                    Vector3       tl, tr, bl, br;
                    rect.BoxBounds(out tl, out tr, out bl, out br);
                    RasterizeBox(squares, f.rasterizationGrid, tl, tr, bl, br);
                }
            }
            yield return(null);

            if (f.Paths != null)
            {
                foreach (FloorPath p in f.Paths)
                {
                    foreach (Edge e in p.Edges)
                    {
                        Vector3 tl, tr, bl, br;
                        GenerationUtility.BoxBounds(e.Start, e.End, e.Width, out tl, out tr, out bl, out br);
                        RasterizeBox(squares, f.rasterizationGrid, tl, tr, bl, br);
                        if (!e.TailEdge)
                        {
                            RasterizeCircle(squares, f.rasterizationGrid, e.End, e.Width / 2f);
                        }
                    }
                }
            }

            f.Squares = squares;
        }
        private bool IsInRoom(Vector3 pos, Room r1, Room r2)
        {
            Vector3 tl, tr, bl, br;

            if (r1 is CircleRoom)
            {
                if (GenerationUtility.PointInCircle(pos, r1.Position, ((CircleRoom)r1).Radius))
                {
                    return(true);
                }
            }
            else
            {
                RectangleRoom rect = (RectangleRoom)r1;
                rect.BoxBounds(out tl, out tr, out bl, out br);
                if (GenerationUtility.PointInBox(pos, tl, tr, bl, br))
                {
                    return(true);
                }
            }

            if (r2 is CircleRoom)
            {
                if (GenerationUtility.PointInCircle(pos, r2.Position, ((CircleRoom)r2).Radius))
                {
                    return(true);
                }
            }
            else
            {
                RectangleRoom rect = (RectangleRoom)r2;
                rect.BoxBounds(out tl, out tr, out bl, out br);
                if (GenerationUtility.PointInBox(pos, tl, tr, bl, br))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #6
0
 private static bool checkOfCoverageOfRoom(Gene gene, RectangleRoom room)
 {
     if (room.X1 < room.X2)
     {
         if (room.Y1 < room.Y4)
         {
             if (gene.OX > room.X1 && gene.OX < room.X2 && gene.OY > room.Y1 && gene.OY < room.Y4)
             {
                 return(true);
             }
         }
         else
         {
             if (gene.OX > room.X1 && gene.OX < room.X2 && gene.OY < room.Y1 && gene.OY > room.Y4)
             {
                 return(true);
             }
         }
     }
     else
     {
         if (room.Y1 < room.Y4)
         {
             if (gene.OX < room.X1 && gene.OX > room.X2 && gene.OY > room.Y1 && gene.OY < room.Y4)
             {
                 return(true);
             }
         }
         else
         {
             if (gene.OX < room.X1 && gene.OX > room.X2 && gene.OY < room.Y1 && gene.OY > room.Y4)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #7
0
        private void InitializeAllObjects()
        {
            SchemeOfBuilding scheme = null;

            try
            {
                scheme = _Context.Schemes.Where(c => c.ProjectNumber.ProjectId.Equals(_projectId)).First();
            }
            catch
            {
                MessageBox.Show("Ошибка загрузки данных из базы данных");
            }
            List <Room> rooms = null;

            if (scheme.Rooms != null)
            {
                if (scheme.Rooms.Count() > 0)
                {
                    rooms = scheme.Rooms;

                    foreach (Room room in rooms)
                    {
                        int coord_X1 = room.Coord_X1;
                        int coord_Y1 = room.Coord_Y1;

                        int coord_X2 = room.Coord_X2;
                        int coord_Y2 = room.Coord_Y2;

                        int coord_X3 = room.Coord_X3;
                        int coord_Y3 = room.Coord_Y3;

                        int coord_X4 = room.Coord_X4;
                        int coord_Y4 = room.Coord_Y4;

                        Line lin = new Line
                        {
                            Stroke          = color,
                            StrokeThickness = SIZE,
                            X1 = coord_X1,
                            Y1 = coord_Y1,
                            X2 = coord_X2,
                            Y2 = coord_Y2,
                            StrokeStartLineCap = PenLineCap.Round,
                            StrokeEndLineCap   = PenLineCap.Round
                        };

                        Line lin2 = new Line
                        {
                            Stroke          = color,
                            StrokeThickness = SIZE,
                            X1 = coord_X1,
                            Y1 = coord_Y1,
                            X2 = coord_X3,
                            Y2 = coord_Y3,
                            StrokeStartLineCap = PenLineCap.Round,
                            StrokeEndLineCap   = PenLineCap.Round
                        };

                        Line lin3 = new Line
                        {
                            Stroke          = color,
                            StrokeThickness = SIZE,
                            X1 = coord_X3,
                            Y1 = coord_Y3,
                            X2 = coord_X4,
                            Y2 = coord_Y4,
                            StrokeStartLineCap = PenLineCap.Round,
                            StrokeEndLineCap   = PenLineCap.Round
                        };

                        Line lin4 = new Line
                        {
                            Stroke          = color,
                            StrokeThickness = SIZE,
                            X1 = coord_X2,
                            Y1 = coord_Y2,
                            X2 = coord_X4,
                            Y2 = coord_Y4,
                            StrokeStartLineCap = PenLineCap.Round,
                            StrokeEndLineCap   = PenLineCap.Round
                        };

                        CanvasAreaForSchemeOfRoom.Children.Add(lin);
                        CanvasAreaForSchemeOfRoom.Children.Add(lin2);
                        CanvasAreaForSchemeOfRoom.Children.Add(lin3);
                        CanvasAreaForSchemeOfRoom.Children.Add(lin4);

                        RectangleRoom rectRoom = new RectangleRoom();
                        rectRoom.X1 = room.Coord_X1;
                        rectRoom.Y1 = room.Coord_Y1;
                        rectRoom.X2 = room.Coord_X2;
                        rectRoom.Y2 = room.Coord_Y2;
                        rectRoom.X3 = room.Coord_X3;
                        rectRoom.Y3 = room.Coord_Y3;
                        rectRoom.X4 = room.Coord_X4;
                        rectRoom.Y4 = room.Coord_Y4;
                        SingleSpaceParams.getInstance().Rooms.Add(rectRoom);
                    }
                }
            }

            if (scheme.Point != null)
            {
                List <ControlPoint> points = null;
                if (scheme.Point.Count > 0)
                {
                    points = scheme.Point;

                    foreach (ControlPoint point in points)
                    {
                        pointLine = new Line
                        {
                            Stroke = new SolidColorBrush
                            {
                                Color = Colors.Red,
                            },
                            StrokeThickness = 10,
                            X1 = point.Coord_X,
                            Y1 = point.Coord_Y,
                            X2 = point.Coord_X + 1,
                            Y2 = point.Coord_Y + 1,
                            StrokeStartLineCap = PenLineCap.Round,
                            StrokeEndLineCap   = PenLineCap.Round,
                        };
                        CanvasAreaForSchemeOfRoom.Children.Add(pointLine);

                        ControlPointInst controlPoint = new ControlPointInst(
                            Convert.ToInt32(point.Coord_X),
                            Convert.ToInt32(point.Coord_Y));

                        SingleSpaceParams.getInstance().ControlPoints.Add(controlPoint);
                    }
                }
            }

            if (scheme.Positions != null)
            {
                try
                {
                    List <InstallationPosition> positions = scheme.Positions;

                    foreach (InstallationPosition pos in positions)
                    {
                        PlacmentOfModules placement = pos.Placment.First();
                        ModelsOfModules   model     = _Context.Models.Where(mod => mod.ModuleId == placement.ModelId).First();

                        EllipseGeometry el = new EllipseGeometry
                        {
                            Center  = new Point(pos.Coord_X, pos.Coord_Y),
                            RadiusX = double.Parse(model.ModelRadius),
                            RadiusY = double.Parse(model.ModelRadius)
                        };
                        Path path = new Path();
                        path.Data            = el;
                        path.StrokeThickness = 2;
                        path.Opacity         = 0.5;
                        path.Fill            = new SolidColorBrush
                        {
                            Color   = Colors.LightBlue,
                            Opacity = 0.7
                        };
                        path.Stroke = new SolidColorBrush
                        {
                            Color = Colors.Red
                        };
                        CanvasAreaForSchemeOfRoom.Children.Add(path);
                    }
                }
                catch
                {
                    MessageBox.Show("Ошибка загрузки данных из базы данных");
                }
            }
            _Models = _Context.Models.ToList();
        }
Example #8
0
        private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_IsRoom)
            {
                widthRoomTextBlock.Visibility      = Visibility.Collapsed;
                widthRoomTextBox.Visibility        = Visibility.Collapsed;
                lengthRoomTextBlock.Visibility     = Visibility.Collapsed;
                lengthRoomTextBox.Visibility       = Visibility.Collapsed;
                setLengthAndWidthButton.Visibility = Visibility.Collapsed;

                if (line != null && line2 != null)
                {
                    RectangleRoom room = new RectangleRoom
                    {
                        X1 = Convert.ToInt32(line.X1),
                        Y1 = Convert.ToInt32(line.Y1),

                        X2 = Convert.ToInt32(line.X2),
                        Y2 = Convert.ToInt32(line.Y2),

                        X3 = Convert.ToInt32(line2.X2),
                        Y3 = Convert.ToInt32(line2.Y2),

                        X4 = Convert.ToInt32(line4.X2),
                        Y4 = Convert.ToInt32(line4.Y2)
                    };
                    // SingleSpaceParams.getInstance().Rooms.Add(room);
                }

                line    = null;
                line2   = null;
                line3   = null;
                line4   = null;
                isPaint = false;
            }

            if (_IsPoint)
            {
                var point = Mouse.GetPosition(CanvasAreaForSchemeOfRoom);
                pointLine = new Line
                {
                    Stroke = new SolidColorBrush
                    {
                        Color = Colors.Red,
                    },
                    StrokeThickness = 10,
                    X1 = point.X,
                    Y1 = point.Y,
                    X2 = point.X + 1,
                    Y2 = point.Y + 1,
                    StrokeStartLineCap = PenLineCap.Round,
                    StrokeEndLineCap   = PenLineCap.Round,
                };
                ControlPointInst controlPoint = new ControlPointInst(
                    Convert.ToInt32(pointLine.X1),
                    Convert.ToInt32(pointLine.Y1));

                SingleSpaceParams.getInstance().ControlPoints.Add(controlPoint);
                CanvasAreaForSchemeOfRoom.Children.Add(pointLine);
            }
        }