Ejemplo n.º 1
0
        public void Example()
        {
            Name = "Elements_GridLine";

            // <example>
            var gridData = new List <(string name, Vector3 origin)>()
            {
                ("A", new Vector3()),
                ("B", new Vector3(10, 0, 0)),
                ("C", new Vector3(20, 0, 0)),
                ("D", new Vector3(30, 0, 0)),
            };

            var texts    = new List <(Vector3 location, Vector3 facingDirection, Vector3 lineDirection, string text, Color?color)>();
            var radius   = 1;
            var material = new Material("Red", Colors.Red);

            foreach (var(name, origin) in gridData)
            {
                var gridline = new GridLine
                {
                    Name     = name,
                    Curve    = new Line(origin, origin + new Vector3(25, 25, 0)),
                    Material = material,
                    Radius   = radius
                };
                gridline.AddTextToCollection(texts, Colors.Black);
                this.Model.AddElement(gridline);
            }
            // </example>

            this.Model.AddElement(new ModelText(texts, FontSize.PT72, 50));
        }
Ejemplo n.º 2
0
        public void Example()
        {
            this.Name = "Elements_GridLines";

            var gridData = new List <(string name, Vector3 origin)>()
            {
                ("A", new Vector3()),
                ("B", new Vector3(10, 0, 0)),
                ("C", new Vector3(20, 0, 0)),
                ("D", new Vector3(30, 0, 0)),
            };

            var texts    = new List <(Vector3 location, Vector3 facingDirection, Vector3 lineDirection, string text, Color?color)>();
            var radius   = 1;
            var material = new Material("Red", new Color(1, 0, 0, 1));

            foreach (var(name, origin) in gridData)
            {
                var gridline = new GridLine();
                gridline.Name     = name;
                gridline.Curve    = new Line(origin, origin + new Vector3(25, 25, 0));
                gridline.Material = material;
                gridline.Radius   = radius;
                gridline.AddTextToCollection(texts, Colors.White);
                this.Model.AddElement(gridline);
            }

            this.Model.AddElement(new ModelText(texts, FontSize.PT72, 50));
        }
        /// <summary>
        /// Sets the grid lines.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="table">The table.</param>
        internal static void SetGRID_LINES(Model model, List <Dictionary <string, string> > table)
        {
            foreach (Dictionary <string, string> tableRow in table)
            {
                string   name     = tableRow["CoordSys"];
                GridLine gridLine = new GridLine()
                {
                    AxisDirection  = Enums.EnumLibrary.ConvertStringToEnumByDescription <eDirection>(tableRow["AxisDir"]),
                    GridID         = tableRow["GridID"],
                    Coordinate     = Adaptor.toDouble(tableRow["XRYZCoord"]),
                    LineType       = Enums.EnumLibrary.ConvertStringToEnumByDescription <eLineType>(tableRow["LineType"]),
                    LineColor      = tableRow["LineColor"],
                    Visible        = Adaptor.fromYesNo(tableRow["Visible"]),
                    BubbleLocation = Enums.EnumLibrary.ConvertStringToEnumByDescription <eBubbleLocation>(tableRow["BubbleLoc"])
                };
                if (tableRow.ContainsKey("AllVisible"))
                {
                    gridLine.AllVisible = Adaptor.fromYesNo(tableRow["AllVisible"]);
                    gridLine.BubbleSize = Adaptor.toDouble(tableRow["BubbleSize"]);
                }

                GridLines gridLines = null;
                if (name == CoordinateSystems.Global)
                {
                    gridLines = model.Settings.ModelInformation.CoordinateSystems.GlobalCoordinateSystem.GridLines;
                }
                else
                {
                    CoordinateSystem coordinateSystem = model.Settings.ModelInformation.CoordinateSystems.UserCoordinateSystems.First(c => c.Name == name);
                    gridLines = coordinateSystem.GridLines;
                }
                gridLines?.Lines.Add(gridLine);
            }
        }
Ejemplo n.º 4
0
    private GridLine DoGridLine(int index, Direction direction)
    {
        GridLine gridLine = new GridLine();

        gridLine.GridVertices = DoGridPointPair(index, direction);

        return(gridLine);
    }
Ejemplo n.º 5
0
        private int AddLineInternal(ArrangementType arrType, int minHeight, int maxHeight)
        {
            var elem = new GridLine(this, arrType, minHeight);

            elem.prefValue = maxHeight;
            elementList.Add(elem);
            return(elementList.Count - 1);
        }
 public static dynamic GetTSObject(GridLine dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
Ejemplo n.º 7
0
        public void CurvedGridline()
        {
            Name = nameof(CurvedGridline);

            var size  = 10;
            var texts = new List <(Vector3 location, Vector3 facingDirection, Vector3 lineDirection, string text, Color?color)>();

            // Semicircle
            var gridline = new GridLine
            {
                Name               = "A",
                Material           = new Material("Red", new Color(1, 0, 0, 1)),
                Curve              = new Arc(new Vector3(size, 0, 0), size, 0, 180),
                ExtensionBeginning = size / 2,
                ExtensionEnd       = size / 2,
            };

            gridline.AddTextToCollection(texts, Colors.White);

            // Bezier
            var bezierGridline = new GridLine
            {
                Name  = "B",
                Curve = new Bezier(new List <Vector3>()
                {
                    new Vector3(0, size * 2, 0), new Vector3(size, size * 3, 0), new Vector3(size * 2, size * 2, 0), new Vector3(size * 3, size * 3, 0)
                }),
                Material = new Material("Yellow", new Color(1, 1, 0, 1))
            };

            bezierGridline.AddTextToCollection(texts, Colors.White);

            // Polyline
            var polyGridline = new GridLine
            {
                Name  = "C",
                Curve = new Polyline(new List <Vector3>()
                {
                    new Vector3(0, size * 3, 0), new Vector3(size, size * 4, 0), new Vector3(size * 2, size * 3, 0), new Vector3(size * 3, size * 4, 0)
                }),
                Material = new Material("Green", new Color(0, 1, 0, 1))
            };

            polyGridline.AddTextToCollection(texts, Colors.White);

            // Vertical
            var verticalGridline = new GridLine
            {
                Name     = "D",
                Curve    = new Line(new Vector3(), new Vector3(0, 0, 50)),
                Material = new Material("Blue", new Color(0, 0, 1, 1))
            };

            verticalGridline.AddTextToCollection(texts, Colors.White);

            this.Model.AddElements(gridline, bezierGridline, polyGridline, verticalGridline, new ModelText(texts, FontSize.PT72, 50));
        }
        private static GridLine CreateGridLine(ICurve baseLine, string label, string units)
        {
            GridLine gridLine = new GridLine();

            gridLine.baseLine = baseLine;
            gridLine.label    = label;
            gridLine.units    = units;
            return(gridLine);
        }
Ejemplo n.º 9
0
    void CreateGrid()
    {
        Cells = new Cell[Width, Height];
        Vector2 offset = this.transform.position;

        // Organize the grid objects
        GameObject gridLineContainer = new GameObject("GridLines");
        GameObject cellContainer     = new GameObject("Cells");

        gridLineContainer.transform.parent = this.transform;
        cellContainer.transform.parent     = this.transform;

        // vertical grid lines
        VerticalLines = new GridLine[Width + 1];
        for (int x = 0; x < Width + 1; x++)
        {
            GridLine line = (GameObject.Instantiate(Resources.Load("GridLine") as GameObject)).GetComponent <GridLine> ();
            float    xpos = offset.x + (CellSize * x) + (LineWidth * x);
            line.Set(LineColor, new Vector2(xpos, offset.y), new Vector2(LineWidth, (Height * CellSize) + LineWidth * Height + LineWidth));
            line.transform.parent = gridLineContainer.transform;
            VerticalLines [x]     = line;
        }

        // horizontal grid lines
        HorizontalLines = new GridLine[Height + 1];
        for (int y = 0; y < Height + 1; y++)
        {
            GridLine line = (GameObject.Instantiate(Resources.Load("GridLine") as GameObject)).GetComponent <GridLine> ();
            float    ypos = offset.y - (CellSize * y) - (LineWidth * y);
            line.Set(LineColor, new Vector2(offset.x, ypos), new Vector2((Width * CellSize) + LineWidth * Width + LineWidth, LineWidth));
            line.transform.parent = gridLineContainer.transform;
            HorizontalLines [y]   = line;
        }

        // Cells
        for (int x = 0; x < Width; x++)
        {
            for (int y = 0; y < Height; y++)
            {
                Cell  cell = (GameObject.Instantiate(Resources.Load("Cell") as GameObject)).GetComponent <Cell>();
                float xpos = offset.x + (x * CellSize) + (LineWidth * x) + LineWidth;
                float ypos = offset.y - (y * CellSize) - (LineWidth * y) - LineWidth;
                cell.Set(x, y, new Vector2(xpos, ypos), CellSize, LiquidFlowSprites, ShowFlow, RenderDownFlowingLiquid, RenderFloatingLiquid);

                // add a border
                if (x == 0 || y == 0 || x == Width - 1 || y == Height - 1)
                {
                    cell.SetType(CellType.Solid);
                }

                cell.transform.parent = cellContainer.transform;
                Cells [x, y]          = cell;
            }
        }
        UpdateNeighbors();
    }
Ejemplo n.º 10
0
 public void Init(GameObject root)
 {
     this.Root = root;
     for(int i = 0;i<LineNum;i++)
     {
         GridLine newLine = new GridLine();
         newLine.Init(this,i);
         mGridLineGroup[i]=newLine;
     }
 }
Ejemplo n.º 11
0
    public void CreateMapBySize()
    {
        ClearMap();

        if (null == pointParent)
        {
            pointParent = GameObject.CreatePrimitive(PrimitiveType.Quad).transform;
            pointParent.SetParent(transform);
            pointParent.gameObject.name = "PointParent";
        }

        if (null == lineParent)
        {
            lineParent = GameObject.CreatePrimitive(PrimitiveType.Quad).transform;
            lineParent.SetParent(transform);
            lineParent.gameObject.name = "LineParent";
        }

        if (null == blockParent)
        {
            blockParent = GameObject.CreatePrimitive(PrimitiveType.Quad).transform;
            blockParent.SetParent(transform);
            blockParent.gameObject.name = "BlockParent";
        }

        points = new List <GridPoint>();
        lines  = new List <GridLine>();
        blocks = new List <GridBlock>();

        for (int y = 1; y <= sizeX; y++)
        {
            for (int x = 1; x <= sizeY; x++)
            {
                GridPoint p = CreatePoint(x, y);

                if (x != sizeX)
                {
                    //line
                    GridLine lineH = CreateLine(x, y, true);
                }

                if (y != sizeY)
                {
                    GridLine lineV = CreateLine(x, y, false);
                }

                //Block
                if (x != sizeX && y != sizeY)
                {
                    GridBlock b = CreateBlock(x, y, 1);
                }
            }
        }
    }
        public ETABSGridLines gridLinesToSpeckle(string name)
        {
            double Xo          = 0;
            double Yo          = 0;
            double RZ          = 0;
            string GridSysType = null;
            int    NumXLines   = 0;
            int    NumYLines   = 0;

            string[] GridLineIDX = null;
            string[] GridLineIDY = null;
            double[] OrdinateX   = null;
            double[] OrdinateY   = null;
            bool[]   VisibleX    = null;
            bool[]   VisibleY    = null;
            string[] BubbleLocX  = null;
            string[] BubbleLocY  = null;

            Model.GridSys.GetGridSys_2(name, ref Xo, ref Yo, ref RZ, ref GridSysType, ref NumXLines, ref NumYLines, ref GridLineIDX, ref GridLineIDY, ref OrdinateX, ref OrdinateY, ref VisibleX, ref VisibleY, ref BubbleLocX, ref BubbleLocY);

            var gridlines = new List <GridLine> {
            };
            ETABSGridLines speckleGridLines = new ETABSGridLines();

            speckleGridLines.gridLines = gridlines;

            if (GridSysType == "Cartesian")
            {
                for (int i = 0; i < NumXLines; i++)
                {
                    var pt1      = new Point(OrdinateX[i], OrdinateY[0], units: ModelUnits());
                    var pt2      = new Point(OrdinateX[i], OrdinateY[NumYLines - 1], units: ModelUnits());
                    var gridline = new GridLine(new Line(pt1, pt2, ModelUnits()));
                    gridline.label = GridLineIDX[i];
                    speckleGridLines.gridLines.Add(gridline);
                }
                for (int j = 0; j < NumYLines; j++)
                {
                    var pt1      = new Point(OrdinateX[0], OrdinateY[j], units: ModelUnits());
                    var pt2      = new Point(OrdinateX[NumXLines - 1], OrdinateY[j], units: ModelUnits());
                    var gridline = new GridLine(new Line(pt1, pt2, ModelUnits()));
                    gridline.label = GridLineIDY[j];
                    speckleGridLines.gridLines.Add(gridline);
                }
                speckleGridLines.GridSystemType = GridSysType;
                speckleGridLines.Xo             = Xo;
                speckleGridLines.Yo             = Yo;
                speckleGridLines.Rz             = RZ;
            }


            SpeckleModel.elements.Add(speckleGridLines);
            return(speckleGridLines);
        }
Ejemplo n.º 13
0
        public GridLine GridLineToSpeckle(DB.Grid revitGridLine)
        {
            var speckleGridline = new GridLine();

            speckleGridline.baseLine = CurveToSpeckle(revitGridLine.Curve);
            speckleGridline.label    = revitGridLine.Name;

            //speckleGridline.elementId = revitCurve.Id.ToString(); this would need a RevitGridLine element
            speckleGridline.applicationId = revitGridLine.UniqueId;
            speckleGridline.units         = ModelUnits;
            return(speckleGridline);
        }
Ejemplo n.º 14
0
            private TemplateBuilder GridLine(Orientation orientation, GridPoint startGridPoint, int length, Pen pen, GridPlacement?placement)
            {
                IReadOnlyList <GridTrack> gridTracks;

                if (orientation == Orientation.Horizontal)
                {
                    gridTracks = Template.GridColumns;
                }
                else
                {
                    gridTracks = Template.GridRows;
                }

                if (startGridPoint.X > Template.GridColumns.Count || startGridPoint.Y > Template.GridRows.Count)
                {
                    throw new ArgumentOutOfRangeException(nameof(startGridPoint));
                }

                if (length <= 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(length));
                }

                if (pen == null)
                {
                    pen = DefaultGridLinePen;
                }

                int endGridPointX = startGridPoint.X;
                int endGridPointY = startGridPoint.Y;

                if (orientation == Orientation.Horizontal)
                {
                    endGridPointX += length;
                    if (endGridPointX > Template.GridColumns.Count)
                    {
                        throw new ArgumentOutOfRangeException(nameof(length));
                    }
                }
                else
                {
                    endGridPointY += length;
                    if (endGridPointY > Template.GridRows.Count)
                    {
                        throw new ArgumentOutOfRangeException(nameof(length));
                    }
                }

                var gridLine = new GridLine(startGridPoint, new GridPoint(endGridPointX, endGridPointY), pen, placement);

                Template.AddGridLine(gridLine);
                return(this);
            }
Ejemplo n.º 15
0
        public static Grid ToNative(this GridLine myGridLine)
        {
            var(docObj, stateObj) = GetExistingElementByApplicationId(myGridLine.ApplicationId, myGridLine.Type);

            // If no doc object, means we need to create it!
            if (docObj == null)
            {
                var res = Grid.Create(Doc, Autodesk.Revit.DB.Line.CreateBound(new XYZ(myGridLine.Value[0] * Scale, myGridLine.Value[1] * Scale, 0), new XYZ(myGridLine.Value[3] * Scale, myGridLine.Value[4] * Scale, 0)));
                return(res);
            }

            // if the new and old have the same id (hash equivalent) and the doc obj is not marked as being modified, return the doc object
            if (docObj != null && myGridLine._id == stateObj._id && (bool)stateObj.Properties["userModified"] == false)
            {
                return((Grid)docObj);
            }

            // Otherwise, enter "edit" mode: means the doc object has been modfied, or the original source object changed.
            var myGrid   = docObj as Grid;
            var oldStart = myGrid.Curve.GetEndPoint(0);
            var oldEnd   = myGrid.Curve.GetEndPoint(1);

            var newStart = new XYZ(myGridLine.Value[0] * Scale, myGridLine.Value[1] * Scale, 0);
            //var newStart = new XYZ( myGridLine.Value[ 0 ] * Scale, myGridLine.Value[ 1 ] * Scale, myGridLine.Value[ 2 ] * Scale );
            var newEnd = new XYZ(myGridLine.Value[3] * Scale, myGridLine.Value[4] * Scale, 0);
            //var newEnd = new XYZ( myGridLine.Value[ 3 ] * Scale, myGridLine.Value[ 4 ] * Scale, myGridLine.Value[ 5 ] * Scale );

            var translate = newStart.Subtract(oldStart);

            ElementTransformUtils.MoveElement(Doc, myGrid.Id, translate);

            var currentDirection = myGrid.Curve.GetEndPoint(0).Subtract(myGrid.Curve.GetEndPoint(1)).Normalize();
            var newDirection     = newStart.Subtract(newEnd).Normalize();

            var angle = newDirection.AngleTo(currentDirection);

            if (angle > 0.00001)
            {
                var crossProd = newDirection.CrossProduct(currentDirection).Z;
                ElementTransformUtils.RotateElement(Doc, myGrid.Id, Autodesk.Revit.DB.Line.CreateUnbound(newStart, XYZ.BasisZ), crossProd < 0 ? angle : -angle);
            }

            try
            {
                myGrid.SetCurveInView(DatumExtentType.Model, Doc.ActiveView, Autodesk.Revit.DB.Line.CreateBound(newStart, newEnd));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Failed to set grid endpoints.");
            }

            return(myGrid);
        }
        protected void GetRelatedGridLineProperties()
        {
            double distBetweenPointAndStart, distBetweenPointAndEnd;
            Dictionary <GridLine, double> lengths     = new Dictionary <GridLine, double>();
            Dictionary <GridLine, bool>   startLabels = new Dictionary <GridLine, bool>();

            var gridLines = _fatherGrid.GetObjects();

            while (gridLines.MoveNext())
            {
                /* Поиск расстояния между выбранной точкой и концами оси */
                GridLine gl = gridLines.Current as GridLine;
                distBetweenPointAndStart = Distance.PointToPoint(_pickedPoint, gl.StartLabel.CenterPoint);
                distBetweenPointAndEnd   = Distance.PointToPoint(_pickedPoint, gl.EndLabel.CenterPoint);
                /* Заполнение словаря: Ось-Минимальное расстояние до выбранной точки */
                lengths.Add(gl, Math.Min(distBetweenPointAndEnd, distBetweenPointAndStart));

                /* Определение близки ли мы к началу оси */
                if (distBetweenPointAndEnd < distBetweenPointAndStart)
                {
                    _isStartLabel = false;
                }
                else
                {
                    _isStartLabel = true;
                }
                startLabels.Add(gl, _isStartLabel);
            }

            /*
             * Поиск ближайшей оси через сортировку словаря
             * Для малого количества объектов - норм
             */
            var minKeyValue = lengths.OrderBy(kvp => kvp.Value).First();

            _relatedGridLine = minKeyValue.Key;

            /* Близость к началу оси на ближайшей оси */
            _isStartLabel = startLabels[_relatedGridLine];

            /* Размеры рамки */
            if (_isStartLabel)
            {
                _frameHeight = _relatedGridLine.StartLabel.FrameHeight;
                _frameWidth  = _relatedGridLine.StartLabel.FrameWidth;
            }
            else
            {
                _frameHeight = _relatedGridLine.EndLabel.FrameHeight;
                _frameWidth  = _relatedGridLine.EndLabel.FrameWidth;
            }
        }
Ejemplo n.º 17
0
    void Awake()
    {
        gridLines = GetComponentsInChildren <GridLine>();

        //shuffle array order
        for (int i = 0; i < gridLines.Length; i++)
        {
            int      r    = Random.Range(i, gridLines.Length);
            GridLine temp = gridLines[i];
            gridLines[i] = gridLines[r];
            gridLines[r] = temp;
        }
    }
            protected override void OnPaint(ChartGraphics g)
            {
                g.SelectBrush(this.Owner.BackColor);
                GdiFont gdiFont = g.SelectFont(this.Owner.ScaleFont);
                int     fh      = (int)gdiFont.Font.GetHeight();

                this.Owner.Area.SelectGridPen(g);
                g.SetTextColor(this.Owner.ForeColor);
                for (int i = 0; i < _gridLines.Count; i++)
                {
                    GridLine gl = _gridLines[i];
                    g.DrawLine(0, gl.Y, 2, gl.Y);
                    g.TextOut(gl.Desc, 7, gl.Y - fh / 2);
                }
            }
Ejemplo n.º 19
0
        public void GridLineIntersects()
        {
            //
            // TODO: Add test logic	here
            //

            GridLine lineA = new GridLine(new GridVector2(-5, 0),
                                                        new GridVector2(-10, 0));
            GridLine lineB = new GridLine(new GridVector2(0, 5),
                                                        new GridVector2(0, -5));

            GridVector2 intersect = new GridVector2();
            bool result = lineA.Intersects(lineB, out intersect);
            Debug.Assert(result == true);
            Debug.Assert(intersect.X == 0 && intersect.Y == 0);
        }
Ejemplo n.º 20
0
    public void ShowGridLines()
    {
        float lineWidth = 0.05f;

        GridCanvas.SetActive(true);
        for (int i = 0; i <= Width; i++)
        {
            GridLine newLine = GameObjectPoolManager.Instance.Pool_GridLinePool.AllocateGameObject <GridLine>(GridCanvas.transform);
            newLine.Initialize(GridLine.Orient.Vertical, new Vector2(i, 0), lineWidth, Height);
        }
        for (int j = 0; j <= Height; j++)
        {
            GridLine newLine = GameObjectPoolManager.Instance.Pool_GridLinePool.AllocateGameObject <GridLine>(GridCanvas.transform);
            newLine.Initialize(GridLine.Orient.Horizontal, new Vector2(0, j), lineWidth, Width);
        }
    }
Ejemplo n.º 21
0
        // TODO: Create a proper method, this is just fun.
        // TODO: Add parameters (if any? do grids have parameters?)
        public static GridLine ToSpeckle(this Grid myGrid)
        {
            var start = myGrid.Curve.GetEndPoint(0);
            var end   = myGrid.Curve.GetEndPoint(1);

            var myGridLine = new GridLine()
            {
                ApplicationId = myGrid.UniqueId,
                elementId     = myGrid.Id.ToString(),
                Value         = new List <double>()
                {
                    start.X / Scale, start.Y / Scale, start.Z / Scale, end.X / Scale, end.Y / Scale, end.Z / Scale
                },
                parameters = GetElementParams(myGrid)
            };

            myGridLine.ApplicationId = myGrid.UniqueId;
            myGridLine.GenerateHash();
            return(myGridLine);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Adds major, minor or both grid lines to the specified axis. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="axis"><c>Xml</c> node than represent an axis definition.</param>
        /// <param name="model">A <see cref="GridLine"/> value from model.</param>
        /// <param name="documentHelper">Target xml document helper.</param>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="axis" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">If <paramref name="axis" /> is not an axis.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">The value specified is outside the range of valid values.</exception>
        public static void AddAxisGridLinesMode(this XmlNode axis, GridLine model, IXmlHelper documentHelper)
        {
            SentinelHelper.ArgumentNull(axis, nameof(axis));
            SentinelHelper.IsEnumValid(model);
            SentinelHelper.IsFalse(axis.Name.Contains("catAx") || axis.Name.Contains("valAx") || axis.Name.Contains("dateAx"), "Imposible extraer tipo. el nodo no es de tipo eje");

            var existMajorGridLinesNode = documentHelper.TryGetElementFrom(axis, "c:majorGridlines", out var majorGridLinesElement);

            if (existMajorGridLinesNode)
            {
                var parent = majorGridLinesElement.ParentNode;
                parent.RemoveChild(majorGridLinesElement);
            }

            var existMinorGridLinesNode = documentHelper.TryGetElementFrom(axis, "c:minorGridlines", out var minorGridLinesElement);

            if (existMinorGridLinesNode)
            {
                var parent = minorGridLinesElement.ParentNode;
                parent.RemoveChild(minorGridLinesElement);
            }

            switch (model)
            {
            case GridLine.None:
                break;

            case GridLine.Major:
                axis.AppendChild(majorGridLinesElement);
                break;

            case GridLine.Minor:
                axis.AppendChild(minorGridLinesElement);
                break;

            case GridLine.Both:
                axis.AppendChild(majorGridLinesElement);
                axis.AppendChild(minorGridLinesElement);
                break;
            }
        }
Ejemplo n.º 23
0
    GridLine CreateLine(int x, int y, bool isHorizontal)
    {    //need simpifying
        if (isHorizontal)
        {
            GridLine lineH =             //Horizontal
                             Instantiate(linePrefab,
                                         transform.position + new Vector3((float)((x + 0.5f) * unitDist), -y * unitDist, 0),
                                         Quaternion.identity)
                             .GetComponentInChildren <GridLine>();

            lineH.posX = x;
            lineH.posY = y;
            lineH.SetHorizontal(true);

            lines.Add(lineH);

            lineH.transform.SetParent(lineParent);
            lineH.transform.localScale = new Vector3(unitDist, unitDist, unitDist);

            return(lineH);
        }
        else
        {
            //Vertical
            GridLine lineV = Instantiate(linePrefab,
                                         transform.position + new Vector3(x * unitDist, -(float)((y + 0.5f) * unitDist), 0),
                                         Quaternion.identity)
                             .GetComponentInChildren <GridLine>();

            lineV.posX = x;
            lineV.posY = y;
            lineV.SetHorizontal(false);

            lines.Add(lineV);

            lineV.transform.SetParent(lineParent);
            lineV.transform.localScale = new Vector3(unitDist, unitDist, unitDist);

            return(lineV);
        }
    }
        public bool CreateGridline()
        {
            //ImportXml.getInstance().loadCanvas("map.xml", WorkspaceWorking);

            if (Support.GRIDLINE == true)
            {
                GridLine.getInstance().CreateGridline();

                foreach (Point point in GridLine.getInstance().mListElements.Keys)
                {
                    Canvas.SetLeft(GridLine.getInstance().mListElements[point], point.cX);
                    Canvas.SetTop(GridLine.getInstance().mListElements[point], point.cY);
                    Canvas.SetZIndex(GridLine.getInstance().mListElements[point], 1);
                    WorkspaceWorking.Children.Add(GridLine.getInstance().mListElements[point]);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 25
0
            public void TestPolygon(PointF[] pts)
            {
                PointF start = pts[0];

                for (int i = 1; i < pts.Length; i++)
                {
                    PointF end = pts[i];

                    if (VectorMath.LineInsideRect(box, start.X, start.Y, end.X, end.Y))
                    {
                        GridLine gl = new GridLine();

                        gl.Start = start;
                        gl.End   = end;

                        lines.Add(gl);
                    }

                    start = end;
                }
            }
Ejemplo n.º 26
0
        public override void Draw(GameTime gameTime)
        {
            #region OldDraw
            //GameRef.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, Matrix.Identity);
            //for (int y = 0; y < map.GetLength(0); y++)
            //{
            //    for (int x = 0; x < map.GetLength(1); x++)
            //    {
            //        GameRef.spriteBatch.Draw(
            //            tileset.Texture,
            //            new Rectangle(
            //                x * Engine.TileWidth,
            //                y * Engine.TileHeight,
            //                Engine.TileWidth,
            //                Engine.TileHeight),
            //                tileset.SourceRectangle[map[x,y]],
            //                Color.White);


            //        base.Draw(gameTime);
            //        GameRef.spriteBatch.End();
            //    }
            #endregion

            GameRef.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, Matrix.Identity);

            ObjManager.Draw(GameRef.spriteBatch);
            if (DevelopmentMode)
            {
                GameRef.spriteBatch.DrawString(menuFont, "Development Mode Active", new Vector2(20, 20), Color.Red);
                GameRef.spriteBatch.DrawString(menuFont, "Position x =" + Mouse.GetState().X.ToString() + "Position Y =  " + Mouse.GetState().Y.ToString() + "", new Vector2(40, 40), Color.White);
                GameRef.spriteBatch.DrawString(menuFont, "Time" + StoryTime.ToString(), new Vector2(60, 60), Color.Red);


                GridLine.renderGrid(GameRef.spriteBatch);
                Grid.Draw(GameRef.spriteBatch);
            }

            GameRef.spriteBatch.End();
        }
Ejemplo n.º 27
0
        private int ComputeLabelLocationOfLat(GridLine gridLine)
        {
            int idx          = gridLine.BeginIndex;
            int count        = gridLine.BeginIndex + gridLine.SegmentCount;
            int retIdx       = -1;
            int i            = 0;
            int canvasHeight = _canvas.Container.Height;
            int canvasWidth  = _canvas.Container.Width;

            for (i = idx; i < count; i++)
            {
                if (_allPixelPoints[i].Y > 0 && _allPixelPoints[i].Y < canvasHeight && _allPixelPoints[i].X > 0 && _allPixelPoints[i].X < canvasWidth)
                {
                    retIdx = i;
                    break;
                }
            }
            if (retIdx == -1 && i == count - 1)//所有顶点都在屏幕外面
            {
                return(-1);
            }
            return(retIdx);
        }
        public bool DestroyGridline()
        {
            if (Support.GRIDLINE == true)
            {
                for (int i = 0; i < WorkspaceWorking.Children.Count; ++i)
                {
                    if (WorkspaceWorking.Children[i] is Rectangle)
                    {
                        Rectangle tempRect = (Rectangle)(WorkspaceWorking.Children[i]);
                        if (tempRect.Tag == Support.gridLine)
                        {
                            WorkspaceWorking.Children.Remove(WorkspaceWorking.Children[i]);
                            --i;
                        }
                    }
                }

                GridLine.getInstance().DestroyGridline();
                Support.GRIDLINE = false;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 29
0
            protected override void OnPaint(ChartGraphics g)
            {
                g.SelectBrush(this.Owner.BackColor);
                GdiFont gdiFont = g.SelectFont(this.Owner.ScaleFont);

                this.Owner.Area.SelectGridPen(g);
                g.SetTextColor(this.Owner.ForeColor);

                for (int i = 0; i < _gridLines.Count; i++)
                {
                    GridLine gl = _gridLines[i];
                    g.DrawLine(gl.X, 0, gl.X, 2);
                    g.TextOut(gl.Desc, gl.X, 3);
                }

                //for (int i = 0; i < _viewCountBar; i++) {
                //  int x = i * this.DeltaX;
                //  int barindex = i + this.Position;
                //  if (Multiple(x, 32)) {
                //    //if (this.HorizontalScaleVisible && this.ChartManager.Bars != null && barindex < barcount) {

                //    //  string sc = "";
                //    //  DateTime dtm = this.ChartManager.Bars[barindex].Time;
                //    //  if (l) {
                //    //    sc = dtm.ToString("d MMM yyyy");
                //    //    l = false;
                //    //  } else
                //    //    sc = dtm.ToString("d MMM ") + dtm.ToShortTimeString();

                //    //  ghscale.DrawLine(_borderPen, _map[i], 0, _map[i], 2);
                //    //  ghscale.DrawString(sc, Manager.Style.ScaleFont, _scaleForeBrush, _map[i], 2);
                //    //}

                //  }
                //}
            }
        /// <summary>
        /// 初始化柱子的轴线;
        /// </summary>
        private void InitCylinderGridLine()
        {
            if (null == mViewBase)
            {
                return;
            }

            DrawingObjectEnumerator gridLines = mViewBase.GetAllObjects(typeof(TSD.GridLine));

            DrawingHandler drawingHandler = new DrawingHandler();

            TSD.UI.DrawingObjectSelector DS = drawingHandler.GetDrawingObjectSelector();

            while (gridLines.MoveNext())
            {
                GridLine gridLine = gridLines.Current as GridLine;

                if (gridLine == null)
                {
                    continue;
                }

                Point startPoint = gridLine.StartLabel.CenterPoint;
                Point endPoint   = gridLine.EndLabel.CenterPoint;

                Vector gridlineDirectionNormal = new Vector(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y, endPoint.Z - startPoint.Z);

                if (!CDimTools.GetInstance().IsTwoVectorParallel(gridlineDirectionNormal, new Vector(1, 0, 0)))
                {
                    continue;
                }

                Point intersectionPoint = CDimTools.GetInstance().ComputeTwoLineIntersectPoint(startPoint, endPoint, new Point(0, 0, 0), new Point(0, 1000, 0));
                mIntersectionPointList.Add(intersectionPoint);
            }
        }
Ejemplo n.º 31
0
        public List <ApplicationPlaceholderObject> GridLineToNative(GridLine speckleGridline)
        {
            var revitGrid = GetExistingElementByApplicationId(speckleGridline.applicationId) as Grid;
            var curve     = CurveToNative(speckleGridline.baseLine).get_Item(0);

            //delete and re-create line
            //TODO: check if can be modified
            if (revitGrid != null)
            {
                if (revitGrid.IsCurved)
                {
                    Doc.Delete(revitGrid.Id); //not sure how to modify arc grids
                }
                else
                {
                    //dim's magic from 1.0
                    var oldStart = revitGrid.Curve.GetEndPoint(0);
                    var oldEnd   = revitGrid.Curve.GetEndPoint(1);

                    var newStart = curve.GetEndPoint(0);
                    var newEnd   = curve.GetEndPoint(1);

                    var translate = newStart.Subtract(oldStart);
                    ElementTransformUtils.MoveElement(Doc, revitGrid.Id, translate);

                    var currentDirection = revitGrid.Curve.GetEndPoint(0).Subtract(revitGrid.Curve.GetEndPoint(1)).Normalize();
                    var newDirection     = newStart.Subtract(newEnd).Normalize();

                    var angle = newDirection.AngleTo(currentDirection);

                    if (angle > 0.00001)
                    {
                        var crossProd = newDirection.CrossProduct(currentDirection).Z;
                        ElementTransformUtils.RotateElement(Doc, revitGrid.Id, Autodesk.Revit.DB.Line.CreateUnbound(newStart, XYZ.BasisZ), crossProd < 0 ? angle : -angle);
                    }

                    try
                    {
                        revitGrid.SetCurveInView(DatumExtentType.Model, Doc.ActiveView, Line.CreateBound(newStart, newEnd));
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Failed to set grid endpoints.");
                    }
                }
            }

            //create the grid
            if (revitGrid == null)
            {
                if (curve is Arc a)
                {
                    revitGrid = Grid.Create(Doc, a);
                }
                else if (curve is Line l)
                {
                    revitGrid = Grid.Create(Doc, l);
                }
                else
                {
                    throw new Speckle.Core.Logging.SpeckleException("Curve type not supported for Grid: " + curve.GetType().FullName);
                }
            }

            //name must be unique, too much faff
            //revitGrid.Name = speckleGridline.label;

            var placeholders = new List <ApplicationPlaceholderObject>()
            {
                new ApplicationPlaceholderObject
                {
                    applicationId          = speckleGridline.applicationId,
                    ApplicationGeneratedId = revitGrid.UniqueId,
                    NativeObject           = revitGrid
                }
            };


            return(placeholders);
        }
Ejemplo n.º 32
0
    private GridLine DoGridLine(int index, Direction direction)
    {
        GridLine gridLine = new GridLine();

        gridLine.GridVertices = DoGridPointPair(index, direction);

        return gridLine;
    }
Ejemplo n.º 33
0
 private void ComputeGridLines(ICoordinateTransform coordTran)
 {
     try
     {
         if (_gridLines != null)
         {
             _gridLines.Clear();
         }
         else
         {
             _gridLines = new List <GridLine>();
         }
         double span = _gridSpan;
         int    idx = 0;
         double prjX, prjY;
         double maxLon = 0d;
         double maxLat = 0d;
         double x = 0d, y = 0d;
         //sample lon lines
         foreach (Range range in _validLonRanges)
         {
             x      = Math.Max(range.MinValue, _beginLon);
             y      = 0;
             maxLon = Math.Min(range.MaxValue, _endLon);
             maxLat = 0;
             while (x <= maxLon)
             {
                 y = Math.Max(_validLatRange.MinValue, _beginLat);
                 GridLine gridLine = new GridLine();
                 gridLine.BeginIndex = idx;
                 maxLat = Math.Min(_validLatRange.MaxValue, _endLat);
                 while (y <= maxLat)
                 {
                     coordTran.Geo2Prj(x, y, out prjX, out prjY);
                     _allPrjPoints[idx].X = (float)prjX;
                     _allPrjPoints[idx].Y = (float)prjY;
                     idx++;
                     y += span;
                 }
                 gridLine.SegmentCount = idx - gridLine.BeginIndex;
                 _gridLines.Add(gridLine);
                 x += span;
             }
         }
         _lonLines = _gridLines.Count;
         foreach (Range range in _validLonRanges)
         {
             //sample lat lines
             y      = _validLatRange.MinValue;
             maxLat = Math.Min(_validLatRange.MaxValue, _endLat);
             while (y <= _validLatRange.MaxValue)
             {
                 GridLine gridLine = new GridLine();
                 gridLine.BeginIndex = idx;
                 x      = range.MinValue;
                 maxLon = Math.Min(range.MaxValue, _endLon);
                 while (x <= maxLon)
                 {
                     coordTran.Geo2Prj(x, y, out prjX, out prjY);
                     _allPrjPoints[idx].X = (float)prjX;
                     _allPrjPoints[idx].Y = (float)prjY;
                     idx++;
                     x += span;
                 }
                 gridLine.SegmentCount = idx - gridLine.BeginIndex;
                 _gridLines.Add(gridLine);
                 y += span;
             }
         }
         _latLines = _gridLines.Count - _lonLines;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }