Example #1
0
 private void DrawDimension(GridSetup grid)
 {
     foreach (var item in interfaceElements)
     {
         item.Uid = "Dimension";
         grid.canvas.Children.Add(item);
     }
 }
Example #2
0
        public void DrawWallDimension(Line wall, GridSetup grid)
        {
            AddExtensionLines(wall);
            AddDimLine(wall);
            AddDimensionTick(dimensionLine);
            AddAnnotation(wall, grid);

            DrawDimension(grid);
        }
Example #3
0
        private Window WindowSetup(GridSetup grid)
        {
            var window = new Window();

            window.Width      = grid.Width;
            window.Height     = grid.Height + 50;
            window.ResizeMode = ResizeMode.NoResize;
            window.Content    = grid;
            window.Background = Brushes.WhiteSmoke;
            window.Topmost    = true;
            return(window);
        }
Example #4
0
        // Constructor
        internal MapManager()
        {
            // Create temporary path
            temppath = General.MakeTempDirname();
            Directory.CreateDirectory(temppath);
            General.WriteLogLine("Temporary directory:  " + temppath);

            // Basic objects
            grid         = new GridSetup();
            undoredo     = new UndoManager();
            copypaste    = new CopyPasteManager();
            launcher     = new Launcher();
            thingsfilter = new NullThingsFilter();
        }
Example #5
0
        internal static GridLayout FromGridSetup(GridSetup gridSetup)
        {
            switch (gridSetup)
            {
            case GridSetup.Three_By_Three:
                return(new GridLayout(5, 3));

            case GridSetup.Five_By_Five:
                return(new GridLayout(8, 5));

            case GridSetup.Seven_By_Seven:
                return(new GridLayout(11, 7));

            default:
                return(new GridLayout(5, 3));
            }
        }
Example #6
0
        public List <PointF> AddElementsPreviewF(GridSetup grid)
        {
            List <PointF>    filteredPoints = new List <PointF>();
            List <UIElement> prewiElements  = grid.canvas.Children.OfType <UIElement>().Where(n => n.Uid.Contains("ElementPreview")).ToList();

            foreach (var item in prewiElements)
            {
                grid.canvas.Children.Remove(item);
            }
            foreach (var item in grid.gridPoints)
            {
                int  counter = 0;
                Line check   = DrawCheckline(item, wpfOutterCheckpoint, wpfOutterCheckpoint);

                foreach (var wall in grid.WpfWalls)
                {
                    PointF intersection = tool.GetIntersection(check, wall);
                    if (CheckIfPointBelongToLine(check, intersection))
                    {
                        if (CheckIfPointBelongToLine(wall, intersection))
                        {
                            counter++;
                        }
                    }
                }

                if (counter % 2 == 0)
                {
                    continue;
                }

                Ellipse el = new Ellipse();
                el.Height = 10;
                el.Width  = 10;
                el.Stroke = Brushes.Tomato;
                el.Fill   = Brushes.Aqua;
                el.Uid    = "ElementPreview";
                Canvas.SetTop(el, item.Y - el.Height / 2);
                Canvas.SetLeft(el, item.X - el.Width / 2);
                filteredPoints.Add(item);
                grid.canvas.Children.Add(el);
            }

            return(filteredPoints);
        }
Example #7
0
        private PointF GetDerrivation(BoundingBoxXYZ box, GridSetup grid)
        {
            PointF derrivationPoint = new PointF();

            PointF roomMin = new PointF();

            roomMin.X = (int)(box.Min.X * FeetToMil);
            roomMin.Y = (int)(box.Min.Y * FeetToMil);

            PointF roomMax = new PointF();

            roomMax.X = (int)(box.Max.X * FeetToMil);
            roomMax.Y = (int)(box.Max.Y * FeetToMil);

            double centerRoomX = roomMin.X / grid.Scale + (roomMax.X / grid.Scale - roomMin.X / grid.Scale) / 2;
            double centerRoomY = roomMin.Y / grid.Scale + (roomMax.Y / grid.Scale - roomMin.Y / grid.Scale) / 2;

            derrivationPoint.X = (float)(grid.CanvasSize / 2 - centerRoomX);
            derrivationPoint.Y = (float)(grid.CanvasSize / 2 + centerRoomY);

            return(derrivationPoint);
        }
Example #8
0
        private void AddAnnotation(Line wall, GridSetup grid)
        {
            Label wallSize = new Label
            {
                Width  = 100,
                Height = 25,
                VerticalContentAlignment   = VerticalAlignment.Bottom,
                HorizontalContentAlignment = allign,
                FontSize   = 14,
                Foreground = lineColor,
                Effect     = null,
                Content    = Math.Round((tool.GetLength(wall) * grid.Scale) + 0.05).ToString()
            };

            wallSize.RenderTransform = new RotateTransform(270 - SetTextAngle(wall), wallSize.Width / 2, wallSize.Height);

            PointF textPosition = tool.GetCenter(dimensionLine);

            Canvas.SetLeft(wallSize, textPosition.X - wallSize.Width / 2);
            Canvas.SetTop(wallSize, textPosition.Y - wallSize.Height);
            wallSize.Uid = "Dimension";
            interfaceElements.Add(wallSize);
        }
Example #9
0
        public void SnapToGrid(Highlight highlight, Vector2D pos, Vector2D lastpos)
        {
            Vector2D newpos = GridSetup.SnappedToGrid(pos, gridsize, gridsizeinv);

            switch (highlight)
            {
            case Highlight.Body:
                Vector2D diff = GridSetup.SnappedToGrid(pos, gridsize, gridsizeinv) - GridSetup.SnappedToGrid(lastpos, gridsize, gridsizeinv);
                Debug.WriteLine("diff: " + (diff).ToString());
                outerleft   += diff.x;
                outerright  += diff.x;
                outertop    += diff.y;
                outerbottom += diff.y;
                break;

            // Outer border
            case Highlight.OuterLeft:
                if (newpos.x < outerright)
                {
                    outerleft = newpos.x;
                }
                break;

            case Highlight.OuterRight:
                if (newpos.x > outerleft)
                {
                    outerright = newpos.x;
                }
                break;

            case Highlight.OuterTop:
                if (newpos.y > outerbottom)
                {
                    outertop = newpos.y;
                }
                break;

            case Highlight.OuterBottom:
                if (newpos.y < outertop)
                {
                    outerbottom = newpos.y;
                }
                break;

            // Outer corners
            case Highlight.OuterTopLeft:
                if (newpos.x < outerright)
                {
                    outerleft = newpos.x;
                }
                if (newpos.y > outerbottom)
                {
                    outertop = newpos.y;
                }
                break;

            case Highlight.OuterTopRight:
                if (newpos.x > outerleft)
                {
                    outerright = newpos.x;
                }
                if (newpos.y > outerbottom)
                {
                    outertop = newpos.y;
                }
                break;

            case Highlight.OuterBottomLeft:
                if (newpos.x < outerright)
                {
                    outerleft = newpos.x;
                }
                if (newpos.y < outertop)
                {
                    outerbottom = newpos.y;
                }
                break;

            case Highlight.OuterBottomRight:
                if (newpos.x > outerleft)
                {
                    outerright = newpos.x;
                }
                if (newpos.y < outertop)
                {
                    outerbottom = newpos.y;
                }
                break;
            }

            UpdateLinesAndPoints();
        }
Example #10
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uiapp = commandData.Application;
            var uidoc = uiapp.ActiveUIDocument;
            var doc   = uidoc.Document;

            var handler = new GridInstallEvent();
            var exEvent = ExternalEvent.Create(handler);

            var grid   = new GridSetup(exEvent, handler);
            var window = WindowSetup(grid);

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

            var  selection = uidoc.Selection;
            Room newRoom   = null;

            //-----User select existing Room first-----
            if (selection.GetElementIds().Count > 0)
            {
                foreach (var item in selection.GetElementIds())
                {
                    var elementType = doc.GetElement(item);
                    if (elementType.ToString() == typeof(Room).ToString())
                    {
                        newRoom = elementType as Room;
                    }
                }
            }

            using (var transaction = new Transaction(doc, "Get room parameters"))
            {
                transaction.Start();
                var view = doc.ActiveView;
                if (newRoom == null)
                {
                    try
                    {
                        if (uidoc.ActiveView.SketchPlane == null || view.GenLevel == null)
                        {
                            TaskDialog.Show("Section View", "Please switch to level view.");
                            return(Result.Cancelled);
                        }

                        var point = selection.PickPoint("Point to create a room");
                        newRoom = doc.Create.NewRoom(view.GenLevel, new UV(point.X, point.Y));
                    }
                    catch (OperationCanceledException)
                    {
                        return(Result.Cancelled);
                    }
                }
                //----------------------------------------------------------------------------------------
                var box = newRoom.get_BoundingBox(view);
                if (box == null)
                {
                    return(Result.Failed);
                }


                PointF roomMin = new PointF();
                roomMin.X = (float)(box.Min.X * FeetToMil);
                roomMin.Y = (float)(box.Min.Y * FeetToMil);

                PointF roomMax = new PointF();
                roomMax.X = (float)(box.Max.X * FeetToMil);
                roomMax.Y = (float)(box.Max.Y * FeetToMil);

                var roomDimensions = new RoomDimensions();
                grid.Scale      = roomDimensions.GetScale(roomMin, roomMax, grid.CanvasSize);
                grid.RevitWalls = roomDimensions.GetWalls(newRoom);
                if (grid.RevitWalls.Count == 0)
                {
                    TaskDialog.Show("Error", "Room not detected");
                    return(Result.Cancelled);
                }
                grid.Derrivation = GetDerrivation(box, grid);

                var bBox = new WpfCoordinates();
                grid.BoundingBoxLines = bBox.GetBoundingBox(roomMin, roomMax, grid);

                SymbolPreselectCheck(window);
                grid.DrawWalls();

                transaction.RollBack();
            }

            grid.TextBoxScale.Text = "Scale 1: " + grid.Scale;

            return(Result.Succeeded);
        }
Example #11
0
 /// <summary>
 /// <inheritdoc />
 /// </summary>
 public Task SetConfiguration(GridSetup grid, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
     //_patch.Load(grid);
     //return Task.CompletedTask;
 }
Example #12
0
        // Disposer
        public void Dispose()
        {
            // Not already disposed?
            if (!isdisposed)
            {
                // Let the plugins know
                General.Plugins.OnMapCloseBegin();

                // Stop processing
                General.MainWindow.StopProcessing();

                // Change to no mode
                General.Editing.ChangeMode((EditMode)null);

                // Unbind any methods
                General.Actions.UnbindMethods(this);

                // Dispose
                if (grid != null)
                {
                    grid.Dispose();
                }
                if (launcher != null)
                {
                    launcher.Dispose();
                }
                if (copypaste != null)
                {
                    copypaste.Dispose();
                }
                if (undoredo != null)
                {
                    undoredo.Dispose();
                }
                General.WriteLogLine("Unloading data resources...");
                if (data != null)
                {
                    data.Dispose();
                }
                General.WriteLogLine("Unloading map data...");
                if (map != null)
                {
                    map.Dispose();
                }
                General.WriteLogLine("Stopping graphics device...");
                if (renderer2d != null)
                {
                    renderer2d.Dispose();
                }
                if (renderer3d != null)
                {
                    renderer3d.Dispose();
                }
                if (graphics != null)
                {
                    graphics.Dispose();
                }
                visualcamera = null;
                grid         = null;
                launcher     = null;
                copypaste    = null;
                undoredo     = null;
                data         = null;
                //tempwad = null;
                map        = null;
                renderer2d = null;
                renderer3d = null;
                graphics   = null;

                // We may spend some time to clean things up here
                GC.Collect();

                // Let the plugins know
                General.Plugins.OnMapCloseEnd();

                // Done
                isdisposed = true;
            }
        }
Example #13
0
 /// <summary>
 /// <inheritdoc />
 /// </summary>
 public Task SetConfiguration(GridSetup grid, CancellationToken cancellationToken)
 {
     return(_hubConnection.InvokeAsync(nameof(SetConfiguration), grid, cancellationToken, cancellationToken));
 }