コード例 #1
0
        private static Point3dCollection SamplePoints(EllipticalArc3d arc, bool isCounterClockwise)
        {
            double num = arc.GetLength(arc.StartAngle, arc.EndAngle, 0.0) / 1000.0;

            PointOnCurve3d[]  samplePoints      = arc.GetSamplePoints(arc.StartAngle, arc.EndAngle, num);
            Point3dCollection point3dCollection = new Point3dCollection();

            if (isCounterClockwise)
            {
                PointOnCurve3d[] array = samplePoints;
                for (int i = 0; i < array.Length; i++)
                {
                    PointOnCurve3d pointOnCurve3d = array[i];
                    point3dCollection.Add(pointOnCurve3d.GetPoint());
                }
            }
            else
            {
                int num2 = samplePoints.Length;
                for (int j = num2 - 1; j >= 0; j--)
                {
                    point3dCollection.Add(samplePoints[j].GetPoint());
                }
            }
            return(point3dCollection);
        }
コード例 #2
0
        public static Point3d?GetOrthoNormalPointEx(this Polyline pline, Point3d point)
        {
            point = point.OrthoProject(pline.GetPlane());

            List <Point3d> res      = new List <Point3d>();
            var            segments = pline.GetSegments();

            foreach (var s in segments)
            {
                Vector3d vector     = point - s.StartPoint;
                Vector3d segmVector = s.EndPoint - s.StartPoint;
                double   cos        = segmVector.GetCos2d(vector);

                double length = s.GetLength(s.GetParameterOf(s.StartPoint),
                                            s.GetParameterOf(s.EndPoint), Tolerance.Global.EqualPoint);


                if (cos >= 0d && cos * vector.Length <= segmVector.Length)
                {
                    if (s is CircularArc3d)
                    {
                        CircularArc3d  arc     = (CircularArc3d)s;
                        Vector3d       central = point - arc.Center;
                        PointOnCurve3d pointOn = null;
                        try
                        {
                            pointOn = s.GetNormalPoint(point, Tolerance.Global);
                        }
                        catch (InvalidOperationException)
                        {
                            continue;
                        }
                        if (pointOn != null)
                        {
                            res.Add(pointOn.Point);
                        }
                    }
                    else if (s is LineSegment3d)
                    {
                        LineSegment3d line   = (LineSegment3d)s;
                        Line          buffer = new Line(line.StartPoint, line.EndPoint);
                        res.Add(buffer.GetPointAtDist(cos * vector.Length));
                    }
                }
            }
            if (res.Count == 0)
            {
                return(null);
            }
            else
            {
                res.Sort((p1, p2) => Comparer <double> .Default.Compare((point - p1).Length, (point - p2).Length));
                return(res[0]);
            }
        }
コード例 #3
0
        public static Point3d?GetOrthoNormalPoint(this Arc arc, Point3d point, bool nullForOutOfRange = true)
        {
            point = point.OrthoProject(arc.GetPlane());

            CircularArc3d  arc3d   = arc.ConvertToCircularArc();
            Vector3d       central = point - arc3d.Center;
            PointOnCurve3d pointOn = null;

            try
            {
                pointOn = arc3d.GetNormalPoint(point, Tolerance.Global);
            }
            catch (InvalidOperationException)
            {
                if (nullForOutOfRange)
                {
                    return(null);
                }
                else
                {
                    if ((point - arc3d.StartPoint).Length < (point - arc3d.EndPoint).Length)
                    {
                        return(arc3d.StartPoint);
                    }
                    else
                    {
                        return(arc3d.EndPoint);
                    }
                }
            }
            if (pointOn != null)
            {
                return(pointOn.Point);
            }



            return(null);
        }
コード例 #4
0
        //update from tehran 7/15
        public void DrawJumper()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions peo = new PromptEntityOptions("");
            PromptEntityResult  perOne, perTwo;
            ObjectId            SharedPole = ObjectId.Null;

            Atend.Base.Acad.AT_INFO conductorInfo;
            Atend.Base.Acad.AT_INFO conductorInfo1;

            #region Conductor One


            peo.Message = "\nSelect First Conductor : ";
            perOne      = ed.GetEntity(peo);
            if (perOne.Status == PromptStatus.OK)
            {
                conductorInfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(perOne.ObjectId);
                if (conductorInfo.ParentCode != "NONE" && (conductorInfo.NodeType == (int)Atend.Control.Enum.ProductType.Conductor || conductorInfo.NodeType == (int)Atend.Control.Enum.ProductType.SelfKeeper || conductorInfo.NodeType == (int)Atend.Control.Enum.ProductType.GroundCabel))
                {
                    JumperBtranch.LeftNodeCode = new Guid(conductorInfo.NodeCode);
                    #region Conductor Two
                    peo.Message = "\nSelect Second Conductor : ";
                    perTwo      = ed.GetEntity(peo);
                    if (perTwo.Status == PromptStatus.OK)
                    {
                        conductorInfo1 = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(perTwo.ObjectId);
                        if (conductorInfo1.ParentCode != "NONE" && (conductorInfo1.NodeType == (int)Atend.Control.Enum.ProductType.Conductor || conductorInfo1.NodeType == (int)Atend.Control.Enum.ProductType.SelfKeeper || conductorInfo1.NodeType == (int)Atend.Control.Enum.ProductType.GroundCabel))
                        {
                            JumperBtranch.RightNodeCode = new Guid(conductorInfo1.NodeCode);
                            JumperBtranch.Number        = "Jumper";
                            ObjectIdCollection     FirstConductorPole  = new ObjectIdCollection();
                            Atend.Base.Acad.AT_SUB firstConductorSub   = Atend.Base.Acad.AT_SUB.SelectBySelectedObjectId(perOne.ObjectId);
                            ObjectIdCollection     SecondConductorPole = new ObjectIdCollection();
                            Atend.Base.Acad.AT_SUB SecondConductorSub  = Atend.Base.Acad.AT_SUB.SelectBySelectedObjectId(perTwo.ObjectId);
                            foreach (ObjectId oi in firstConductorSub.SubIdCollection)
                            {
                                //Atend.Base.Acad.AT_INFO at_info = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(oi);
                                //if (at_info.ParentCode != "NONE" && at_info.NodeType == (int)Atend.Control.Enum.ProductType.Consol)
                                //{
                                Atend.Base.Acad.AT_SUB at_sub = Atend.Base.Acad.AT_SUB.SelectBySelectedObjectId(oi);
                                foreach (ObjectId oii in at_sub.SubIdCollection)
                                {
                                    Atend.Base.Acad.AT_INFO at_poleinfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(oii);

                                    if (at_poleinfo.ParentCode != "NONE" && at_poleinfo.NodeType == (int)Atend.Control.Enum.ProductType.Pole)
                                    {
                                        FirstConductorPole.Add(oii);
                                    }
                                }

                                // }
                            }
                            foreach (ObjectId oi in SecondConductorSub.SubIdCollection)
                            {
                                //Atend.Base.Acad.AT_INFO at_info = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(oi);
                                //if (at_info.ParentCode != "NONE" && at_info.NodeType == (int)Atend.Control.Enum.ProductType.Consol)
                                //{
                                Atend.Base.Acad.AT_SUB at_sub = Atend.Base.Acad.AT_SUB.SelectBySelectedObjectId(oi);
                                foreach (ObjectId oii in at_sub.SubIdCollection)
                                {
                                    Atend.Base.Acad.AT_INFO at_poleinfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(oii);
                                    if (at_poleinfo.ParentCode != "NONE" && at_poleinfo.NodeType == (int)Atend.Control.Enum.ProductType.Pole)
                                    {
                                        SecondConductorPole.Add(oii);
                                    }
                                }

                                //}
                            }

                            foreach (ObjectId oi in FirstConductorPole)
                            {
                                foreach (ObjectId oii in SecondConductorPole)
                                {
                                    if (oi == oii)
                                    {
                                        SharedPole = oi;
                                    }
                                }
                            }



                            // draw arc
                            if (SharedPole != ObjectId.Null)
                            {
                                //Entity ContainerEntity = Atend.Global.Acad.UAcad.GetEntityByObjectID(SharedPole);
                                //Polyline p = ContainerEntity as Polyline;
                                //Point3d CenterPoint = Atend.Global.Acad.UAcad.CenterOfEntity(p);
                                Point3d StartPoint = perOne.PickedPoint;;
                                Point3d EndPoint   = perTwo.PickedPoint;

                                Line firstLine  = (Line)Atend.Global.Acad.UAcad.GetEntityByObjectID(perOne.ObjectId);
                                Line secondLine = (Line)Atend.Global.Acad.UAcad.GetEntityByObjectID(perTwo.ObjectId);
                                if (firstLine != null && secondLine != null)
                                {
                                    //ed.WriteMessage("\nGET CLOSEST POINT \n");
                                    LineSegment3d ls1 = new LineSegment3d(firstLine.StartPoint, firstLine.EndPoint);
                                    LineSegment3d ls2 = new LineSegment3d(secondLine.StartPoint, secondLine.EndPoint);

                                    StartPoint = ls1.GetClosestPointTo(StartPoint).Point;
                                    EndPoint   = ls2.GetClosestPointTo(EndPoint).Point;

                                    PointOnCurve3d pp = ls1.GetClosestPointTo(StartPoint);
                                    if (pp.IsOn(StartPoint))
                                    {
                                    }

                                    pp = ls2.GetClosestPointTo(EndPoint);
                                    if (pp.IsOn(EndPoint))
                                    {
                                    }
                                }

                                Entity a = CreateArcEntity(StartPoint, EndPoint);
                                a.LayerId = firstLine.LayerId;
                                JumperBtranch.ProductCode = conductorInfo.ProductCode;
                                if (SaveJumperData())
                                {
                                    ObjectId NewArc = Atend.Global.Acad.UAcad.DrawEntityOnScreen(a, Atend.Control.Enum.AutoCadLayerName.GENERAL.ToString());

                                    Atend.Base.Acad.AT_INFO jumperinfo = new Atend.Base.Acad.AT_INFO(NewArc);
                                    jumperinfo.NodeCode   = JumperBtranch.Code.ToString();
                                    jumperinfo.ParentCode = "";
                                    ed.WriteMessage("   *** JUMPER PCODE : {0} \n", conductorInfo.ProductCode);
                                    jumperinfo.ProductCode = conductorInfo.ProductCode;
                                    jumperinfo.NodeType    = (int)Atend.Control.Enum.ProductType.Jumper;
                                    jumperinfo.Angle       = 0;
                                    jumperinfo.Insert();


                                    Atend.Base.Acad.AT_SUB jumperSub = new Atend.Base.Acad.AT_SUB(NewArc);
                                    //ed.WriteMessage("JUMPER : {0}\n",perOne.ObjectId);
                                    jumperSub.SubIdCollection.Add(perOne.ObjectId);
                                    //ed.WriteMessage("JUMPER : {0}\n", perTwo.ObjectId);
                                    jumperSub.SubIdCollection.Add(perTwo.ObjectId);
                                    jumperSub.Insert();

                                    Atend.Base.Acad.AT_SUB.AddToAT_SUB(NewArc, perOne.ObjectId);
                                    Atend.Base.Acad.AT_SUB.AddToAT_SUB(NewArc, perTwo.ObjectId);
                                }
                            }
                        }
                        else
                        {
                            return;
                        }
                    }//if (perTwo.Status == PromptStatus.OK)
                    else
                    {
                        return;
                    }

                    #endregion
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }

            #endregion
        }