Beispiel #1
0
        public static bool isSegmentsProjectionOverlapped(LineSegment3d lineseg1, LineSegment3d lineseg2)
        {
            Point3d projectPt1 = lineseg1.GetClosestPointTo(lineseg2.StartPoint).Point;
            Point3d projectPt2 = lineseg1.GetClosestPointTo(lineseg2.EndPoint).Point;

            // after the projection, the two line segments(p1->p2 & p3->p4) may be same
            if ((projectPt1.IsEqualTo(lineseg1.StartPoint) && projectPt2.IsEqualTo(lineseg1.EndPoint)) ||
                (projectPt1.IsEqualTo(lineseg1.EndPoint) && projectPt2.IsEqualTo(lineseg1.StartPoint)))
            {
                return(true);
            }

            // [Daniel] retrun null if no overlap???
            LineSegment3d  projectSeg2 = new LineSegment3d(projectPt1, projectPt2);
            LinearEntity3d overlap     = lineseg1.Overlap(projectSeg2);

            return(overlap != null);
        }
Beispiel #2
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
        }
Beispiel #3
0
        public void DrawMafsal()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //ed.WriteMessage("aaaaa\n");
            PromptKeywordOptions PSO = new PromptKeywordOptions("\nترسیم مفصل");

            PSO.Keywords.Add("New", "New", "New");
            PSO.Keywords.Add("Break", "Break", "Break Cabel");
            PSO.Keywords.Default = "New";
            PromptResult psr = ed.GetKeywords(PSO);

            double MyScale = Atend.Base.Design.DProductProperties.AccessSelectBySoftwareCode((int)Atend.Control.Enum.ProductType.Mafsal).Scale;


            DrawMafsalJig DCP = new DrawMafsalJig(MyScale);

            if (psr.Status == PromptStatus.OK)
            {
                switch (psr.StringResult)
                {
                case "New":

                    bool         Conti = true;
                    PromptResult pr;
                    while (Conti)
                    {
                        pr = ed.Drag(DCP);

                        if (pr.Status == PromptStatus.OK)
                        {
                            Conti = false;
                            Entity entity = DCP.GetEntity();
                            if (SaveMafsalData())
                            {
                                Atend.Global.Acad.UAcad.DrawEntityOnScreen(entity, Atend.Control.Enum.AutoCadLayerName.GENERAL.ToString());
                                Atend.Base.Acad.AT_INFO at_info = new Atend.Base.Acad.AT_INFO(entity.ObjectId);
                                at_info.ParentCode  = "";
                                at_info.NodeCode    = MafsalInfo.Code.ToString();
                                at_info.NodeType    = (int)Atend.Control.Enum.ProductType.Mafsal;
                                at_info.ProductCode = Convert.ToInt32(MafsalInfo.ProductCode);
                                at_info.Insert();
                            }
                        }
                        else
                        {
                            Conti = false;
                        }
                    }
                    break;

                case "Break":

                    PromptEntityOptions peo = new PromptEntityOptions("\nمحل برش کابل را انتخاب نمایید");
                    PromptEntityResult  per = ed.GetEntity(peo);
                    if (per.Status == PromptStatus.OK)
                    {
                        Polyline SelectedCable = Atend.Global.Acad.UAcad.GetEntityByObjectID(per.ObjectId) as Polyline;
                        if (SelectedCable != null)
                        {
                            //////SelectedCable.UpgradeOpen();
                            //////SelectedCable.SetField("Name",new Field("Parisa", true));
                            int     NearestSegmentIndex    = 0;
                            double  NearestSegmentDistance = 100000;
                            Point3d NearestPoint           = Point3d.Origin;
                            for (int counter = 0; counter < SelectedCable.NumberOfVertices - 1; counter++)
                            {
                                LineSegment3d ls1           = new LineSegment3d(SelectedCable.GetPoint3dAt(counter), SelectedCable.GetPoint3dAt(counter + 1));
                                Point3d       SelectedPoint = ls1.GetClosestPointTo(per.PickedPoint).Point;
                                //ed.WriteMessage("SP:{0}\n", SelectedPoint);

                                if (SelectedPoint.DistanceTo(per.PickedPoint) < NearestSegmentDistance)
                                {
                                    NearestSegmentDistance = SelectedPoint.DistanceTo(per.PickedPoint);
                                    NearestSegmentIndex    = counter;
                                    NearestPoint           = SelectedPoint;
                                }
                            }
                            //ed.WriteMessage("SINDEX:{0}\n", NearestSegmentIndex);
                            //seprate Cable

                            Polyline Part1 = new Polyline();
                            Polyline Part2 = new Polyline();
                            for (int counter = 0; counter <= NearestSegmentIndex; counter++)
                            {
                                Part1.AddVertexAt(Part1.NumberOfVertices, SelectedCable.GetPoint2dAt(counter), 0, 0, 0);
                                //ed.WriteMessage("POINT:{0}\n", SelectedCable.GetPoint2dAt(counter));
                            }
                            Part1.AddVertexAt(Part1.NumberOfVertices, new Point2d(NearestPoint.X, NearestPoint.Y), 0, 0, 0);

                            Part2.AddVertexAt(Part2.NumberOfVertices, new Point2d(NearestPoint.X, NearestPoint.Y), 0, 0, 0);
                            for (int counter = NearestSegmentIndex + 1; counter <= SelectedCable.NumberOfVertices - 1; counter++)
                            {
                                Part2.AddVertexAt(Part2.NumberOfVertices, SelectedCable.GetPoint2dAt(counter), 0, 0, 0);
                            }
                            if (SaveMafsalData())
                            {
                                try
                                {
                                    Atend.Base.Acad.AT_INFO LastCableInfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(per.ObjectId);
                                    Atend.Base.Acad.AT_SUB  LastCableSub  = Atend.Base.Acad.AT_SUB.SelectBySelectedObjectId(per.ObjectId);
                                    //ed.WriteMessage("-3\n");
                                    //determine header belong to part1 or part2
                                    ObjectIdCollection Blong1 = new ObjectIdCollection();
                                    ObjectIdCollection Blong2 = new ObjectIdCollection();
                                    foreach (ObjectId oi in LastCableSub.SubIdCollection)
                                    {
                                        Atend.Base.Acad.AT_INFO oiInfo = Atend.Base.Acad.AT_INFO.SelectBySelectedObjectId(oi);
                                        Point3d FirstPoint             = SelectedCable.GetPoint3dAt(0);
                                        //ed.WriteMessage("-3.1\n");
                                        if (oiInfo.ParentCode != "NONE" && FirstPoint != null)
                                        {
                                            //ed.WriteMessage("-3.2\n");
                                            switch ((Atend.Control.Enum.ProductType)oiInfo.NodeType)
                                            {
                                            case Atend.Control.Enum.ProductType.Mafsal:
                                                //ed.WriteMessage("-3.3\n");
                                                if (Atend.Global.Acad.UAcad.CenterOfEntity(Atend.Global.Acad.UAcad.GetEntityByObjectID(oi)) == FirstPoint)
                                                {
                                                    //ed.WriteMessage("-3.4\n");
                                                    Blong1.Add(oi);
                                                }
                                                else
                                                {
                                                    //ed.WriteMessage("-3.5\n");
                                                    Blong2.Add(oi);
                                                }
                                                break;

                                            case Atend.Control.Enum.ProductType.HeaderCabel:
                                                //ed.WriteMessage("-3.6\n");
                                                //ed.WriteMessage("color:{0}\n",curv.ColorIndex);
                                                //ed.WriteMessage("-3.6.1\n");
                                                if (Atend.Global.Acad.UAcad.CenterOfEntity(Atend.Global.Acad.UAcad.GetEntityByObjectID(oi)) == FirstPoint)
                                                {
                                                    //ed.WriteMessage("-3.7\n");
                                                    Blong1.Add(oi);
                                                }
                                                else
                                                {
                                                    //ed.WriteMessage("-3.8\n");
                                                    Blong2.Add(oi);
                                                }
                                                break;

                                            case Atend.Control.Enum.ProductType.ConnectionPoint:
                                                if (Atend.Global.Acad.UAcad.CenterOfEntity(Atend.Global.Acad.UAcad.GetEntityByObjectID(oi)) == FirstPoint)
                                                {
                                                    Blong1.Add(oi);
                                                }
                                                else
                                                {
                                                    Blong2.Add(oi);
                                                }

                                                break;
                                            }
                                        }
                                    }

                                    Entity   MafsalEntiyt     = DCP.GetDemo(NearestPoint);
                                    ObjectId NewDrawnMafsalOI = Atend.Global.Acad.UAcad.DrawEntityOnScreen(MafsalEntiyt, Atend.Control.Enum.AutoCadLayerName.GENERAL.ToString());

                                    Atend.Base.Acad.AT_INFO newinfo1 = new Atend.Base.Acad.AT_INFO(NewDrawnMafsalOI);
                                    newinfo1.ParentCode  = "";
                                    newinfo1.NodeCode    = MafsalInfo.Code.ToString();
                                    newinfo1.NodeType    = (int)Atend.Control.Enum.ProductType.Mafsal;
                                    newinfo1.ProductCode = MafsalInfo.ProductCode;
                                    newinfo1.Insert();



                                    //ed.WriteMessage("-4\n");
                                    Atend.Global.Acad.AcadRemove.DeleteEntityByObjectId(SelectedCable.ObjectId);
                                    //ed.WriteMessage("1\n");
                                    Atend.Global.Acad.UAcad.DrawEntityOnScreen(Part1, Atend.Control.Enum.AutoCadLayerName.MED_GROUND.ToString());
                                    //ed.WriteMessage("2\n");
                                    Atend.Global.Acad.UAcad.DrawEntityOnScreen(Part2, Atend.Control.Enum.AutoCadLayerName.MED_GROUND.ToString());
                                    //ed.WriteMessage("3\n");

                                    Atend.Base.Acad.AT_SUB mafsalsub = new Atend.Base.Acad.AT_SUB(NewDrawnMafsalOI);
                                    mafsalsub.SubIdCollection.Add(Part1.ObjectId);
                                    mafsalsub.SubIdCollection.Add(Part2.ObjectId);
                                    mafsalsub.Insert();
                                    //ed.WriteMessage("4\n");

                                    LastCableInfo.SelectedObjectId = Part1.ObjectId;
                                    LastCableInfo.Insert();
                                    ///ed.WriteMessage("5\n");

                                    LastCableInfo.SelectedObjectId = Part2.ObjectId;
                                    LastCableInfo.Insert();
                                    //ed.WriteMessage("6\n");

                                    Atend.Base.Acad.AT_SUB.AddToAT_SUB(NewDrawnMafsalOI, Part1.ObjectId);

                                    foreach (ObjectId oi in Blong1)
                                    {
                                        Atend.Base.Acad.AT_SUB.AddToAT_SUB(oi, Part1.ObjectId);
                                    }

                                    Atend.Base.Acad.AT_SUB.AddToAT_SUB(NewDrawnMafsalOI, Part2.ObjectId);

                                    foreach (ObjectId oi in Blong2)
                                    {
                                        Atend.Base.Acad.AT_SUB.AddToAT_SUB(oi, Part2.ObjectId);
                                    }
                                }
                                catch (System.Exception ex)
                                {
                                    ed.WriteMessage("~~~{0}~~~~~~\n", ex.Message);
                                }
                            }    //catch ended here
                        }
                    }


                    break;
                }
            }
        }