Ejemplo n.º 1
0
        ///<summary>
        /// Returns an array of Point3d objects from a Point3dCollection.
        ///</summary>
        ///<returns>An array of Point3d objects.</returns>

        public static Point3d[] ToArray(this Point3dCollection pts)
        {
            var res = new Point3d[pts.Count];

            pts.CopyTo(res, 0);
            return(res);
        }
Ejemplo n.º 2
0
        public static Point3dCollection SortPoint3DByCurveParam(Curve curve, Point3dCollection point3Ds)
        {
            var raw3D = new Point3d[point3Ds.Count];

            point3Ds.CopyTo(raw3D, 0);
            Array.Sort(raw3D, new Sort3DByCurveParam(curve));
            return(new Point3dCollection(raw3D));
        }
Ejemplo n.º 3
0
        public static Point3dCollection SortPoint3D(Point3dCollection point3Ds)
        {
            var raw3D = new Point3d[point3Ds.Count];

            point3Ds.CopyTo(raw3D, 0);
            Array.Sort(raw3D, new Sort3DbyX());
            return(new Point3dCollection(raw3D));
        }
Ejemplo n.º 4
0
        protected override bool WorldDraw(WorldDraw draw)
        {
            if (_snapshot)
            {
                if (_points.Count > 0)
                {
                    var vecList = GeneratePointCloud(1, true);

                    // Add the core list to the total set

                    _totalVecs.AddRange(vecList);

                    // Make a copy of the latest set of jigged points

                    var tmp = new Point3d[_points.Count];
                    _points.CopyTo(tmp, 0);

                    // Add the copy to the list of snapshot previews

                    _snapped.Add(new Point3dCollection(tmp));
                }
            }

            short origColor = draw.SubEntityTraits.Color;

            for (int i = 0; i < _snapped.Count; i++)
            {
                // Cycle through colour indeces for each snapshot

                draw.SubEntityTraits.Color = (short)(i + 1);

                // Draw the actual snapshot, one by one

                if (_snapped[i].Count > 0)
                {
                    draw.Geometry.Polypoint(_snapped[i], null, null);
                }
            }

            // Set the colour back to the original

            draw.SubEntityTraits.Color = origColor;

            if (_snapshot)
            {
                // Reset the flag, timer and check whether finished

                _snapshot      = false;
                Finished       = (--_numShots == 0);
                _timer.Enabled = true;
            }
            else
            {
                // This simply draws our points

                if (_points.Count > 0)
                {
                    draw.Geometry.Polypoint(_points, null, null);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        private Tuple <double, double> CalculateArea(Transaction t, Polyline p1, Polyline p2)
        {
            Point3d startPoint1;
            Point3d startPoint2;

            if (p1.StartPoint.X > p2.StartPoint.X)
            {
                startPoint2 = p2.GetClosestPointTo(p1.StartPoint, Vector3d.YAxis, true);
                startPoint1 = p1.StartPoint;
            }
            else
            {
                startPoint1 = p1.GetClosestPointTo(p2.StartPoint, Vector3d.YAxis, true);
                startPoint2 = p2.StartPoint;
            }


            Point3d endPoint1;
            Point3d endPoint2;

            if (p1.EndPoint.X < p2.EndPoint.X)
            {
                endPoint2 = p2.GetClosestPointTo(p1.EndPoint, Vector3d.YAxis, true);
                endPoint1 = p1.EndPoint;
            }
            else
            {
                endPoint1 = p1.GetClosestPointTo(p2.EndPoint, Vector3d.YAxis, true);
                endPoint2 = p2.EndPoint;
            }

            var btr = (BlockTableRecord)t.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite);

            var pts = new Point3dCollection();

            p1.IntersectWith(p2, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero);


            var interArray = new Point3d[pts.Count];

            pts.CopyTo(interArray, 0);
            var interList = interArray.ToList();

            interList.Sort((pt1, pt2) => (int)Math.Floor(pt1.X - pt2.X));
            var interQueue = new Queue <Point3d>(interList);

            var cutArea  = 0.0;
            var fillArea = 0.0;

            var curPolyline = new Polyline();
            var VertexYSum  = 0.0;
            var curInd      = 1;
            var curInterPt  = interQueue.Count > 0? interQueue.Dequeue() : endPoint1;
            var i2          = 0;

            curPolyline.AddVertexAt(0, new Point2d(startPoint1.X, startPoint1.Y), 0, 0, 0);
            VertexYSum += startPoint1.Y;
            curPolyline.AddVertexAt(1, new Point2d(startPoint2.X, startPoint2.Y), 0, 0, 0);

            for (var i = 0; i < p1.NumberOfVertices; i++)
            {
                // Could also get the 3D point here
                var pt = p1.GetPoint2dAt(i);
                if (pt.X <= startPoint1.X)
                {
                    continue;
                }
                if (pt.X > curInterPt.X)
                {
                    var vertexAvY = VertexYSum / curInd;
                    curPolyline.AddVertexAt(curInd++, new Point2d(curInterPt.X, curInterPt.Y), 0, 0, 0);
                    if (curInterPt == endPoint1)
                    {
                        curPolyline.AddVertexAt(curInd++, new Point2d(endPoint2.X, endPoint2.Y), 0, 0, 0);
                    }
                    var reverseList = new List <Point2d>();
                    for (; i2 < p2.NumberOfVertices; i2++)
                    {
                        var pt2 = p2.GetPoint2dAt(i2);
                        if (pt.X <= startPoint1.X)
                        {
                            continue;
                        }
                        if (pt2.X <= curInterPt.X)
                        {
                            reverseList.Add(pt2);
                        }
                        if (pt2.X >= curInterPt.X)
                        {
                            reverseList.Reverse();
                            var vertexYSum2 = 0.0;
                            reverseList.ForEach(p =>
                            {
                                curPolyline.AddVertexAt(curInd++, p, 0, 0, 0);
                                vertexYSum2 += pt.Y;
                            });
                            var vertexAvY2 = vertexYSum2 / reverseList.Count;
                            curPolyline.Closed = true;
                            var isCut = vertexAvY < vertexAvY2;
                            if (isCut)
                            {
                                cutArea += curPolyline.Area;
                            }
                            else
                            {
                                fillArea += curPolyline.Area;
                            }
                            var lPoint = CalculateMedianPoint(curPolyline);
                            var label  = new DBText
                            {
                                TextString = curPolyline.Area.ToString("N", new NumberFormatInfo()
                                {
                                    NumberDecimalDigits = 2
                                }),
                                Height   = 0.2,
                                Position = new Point3d(lPoint.X, lPoint.Y, 0)
                            };

                            btr.AppendEntity(label);
                            t.AddNewlyCreatedDBObject(label, true);

                            if (curInterPt == endPoint1)
                            {
                                return(new Tuple <double, double>(cutArea, fillArea));
                            }
                            curPolyline = new Polyline();
                            VertexYSum  = 0;
                            curInd      = 1;
                            curPolyline.AddVertexAt(0, new Point2d(curInterPt.X, curInterPt.Y), 0, 0, 0);
                            VertexYSum += curInterPt.Y;
                            curInterPt  = interQueue.Count > 0 ? interQueue.Dequeue() : endPoint1;
                            break;
                        }
                    }
                }

                curPolyline.AddVertexAt(curInd++, pt, 0, 0, 0);
                VertexYSum += pt.Y;
            }

            return(new Tuple <double, double>(cutArea, fillArea));
        }
Ejemplo n.º 6
0
        public void ProfileCreator()
        {
            //prompt the user for running line
            PromptEntityOptions promptEntity = new PromptEntityOptions("\nPlease Select Running Line: ");

            promptEntity.SetRejectMessage("Line selected is not a polyline!!");
            promptEntity.AddAllowedClass(typeof(Polyline), true);

            PromptEntityResult entityResult = document.Editor.GetEntity(promptEntity);

            if (entityResult.Status != PromptStatus.OK)
            {
                document.Editor.WriteMessage("Error: Please select a Polyline.");
                return;
            }

            Transaction tr = database.TransactionManager.StartTransaction();
            //Save the polyline
            Polyline runningLine = null;

            using (tr)
            {
                runningLine = tr.GetObject(entityResult.ObjectId, OpenMode.ForRead) as Polyline;
            }

            //create the grid for the profile
            Grid grid = null;

            try
            {
                grid = new Grid(4, runningLine.Length);
                grid.Draw();
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                document.Editor.WriteMessage("error creating grid;" + ex.Message);
            }

            if (grid != null)
            {
                grid.SaveGrid();
            }


            Point3d gradeLineInsPt = grid.InsertionPoint;
            //create a vector to generate the starting point for the gradeline..It 80' from -25 to 0
            Point3d  origin = new Point3d(0, 0, 0);
            Matrix3d matrix = Matrix3d.Displacement(origin.GetVectorTo(new Point3d(0, 100, 0)));

            gradeLineInsPt = gradeLineInsPt.TransformBy(matrix);

            Polyline    gradeLine = new Polyline();
            Transaction trans     = database.TransactionManager.StartTransaction();

            using (trans)
            {
                BlockTable       bt  = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;


                gradeLine.AddVertexAt(0, new Point2d(gradeLineInsPt.X, gradeLineInsPt.Y), 0, 0, 0);
                gradeLine.AddVertexAt(1, new Point2d((gradeLineInsPt.X + runningLine.Length), gradeLineInsPt.Y), 0, 0, 0);
                gradeLine.Layer = "PROFILE";

                btr.AppendEntity(gradeLine);
                trans.AddNewlyCreatedDBObject(gradeLine, true);
                trans.Commit();
            }

            //vertice to create selection fence use runningLine
            SelectionSet selectionSet = CreateFenceUsingPolyline(runningLine, false);

            //if any objects selected
            if (selectionSet != null)
            {
                //find objects that intersect with runningLine
                var objCrossingRunningLine = CrossingRunnngLine(selectionSet, runningLine, gradeLineInsPt);

                Point3dCollection bocPoints = new Point3dCollection();

                //draw profile objects if any
                if (objCrossingRunningLine != null)
                {
                    foreach (var obj in objCrossingRunningLine)
                    {
                        //draw profiles objects of Type = boc
                        if (obj.Type == "boc")
                        {
                            bocPoints.Add(obj.Center);
                        }
                        else
                        {
                            DrawProfileObjects(obj);
                        }
                    }
                }

                if (bocPoints.Count != 0)
                {
                    //convert to array to sort
                    Point3d[] point3s = new Point3d[bocPoints.Count];
                    bocPoints.CopyTo(point3s, 0);
                    Array.Sort(point3s, new sort3dByX());

                    Point3dCollection bocPtsSorted = new Point3dCollection(point3s);

                    DrawProfileDriveway(bocPtsSorted, gradeLine.Length);
                }



                //find boc intersect
                //var bocCrossingRunningLine =
            }

            //bore line
            Polyline bore = gradeLine.GetOffsetCurves(14)[0] as Polyline;

            DrawBoreLine(bore);

            //find intercepting profile objects using fence and filter for only ellipses
            SelectionSet utilitiesCrossingBore = CreateFenceUsingPolyline(bore, true);

            //if any profile ellipses selected
            if (utilitiesCrossingBore != null)
            {
                //DrawBoreBelowUtilities(utilitiesCrossingBore, bore.ObjectId);
            }
        }