Exemple #1
0
        public PipeLine GenerateFromSimpleJoint(SimplePipeJoint pipeJoint, Point3d ePoint, double width)
        {
            //

            this.CenterPoint = pipeJoint.CenterPoint;
            PipeLine pipeline1 = pipeJoint.GetConnectedPipeLine(0);
            PipeLine pipeline2 = pipeJoint.GetConnectedPipeLine(1);
            Point3d  p1        = CenterPoint + (pipeline1.Point(0) - CenterPoint).GetNormal() * Length;
            Point3d  p2        = CenterPoint + (pipeline2.Point(0) - CenterPoint).GetNormal() * Length;
            Point3d  p3        = CenterPoint + (ePoint - CenterPoint).GetNormal() * Length;

            if (pipeline1.HeadConnectedObject == pipeJoint)
            {
                pipeline1.HeadConnectedObject = this;
                pipeline1.UpdateStartPoint(p1);
            }
            if (pipeline1.TailConnectedObject == pipeJoint)
            {
                pipeline1.TailConnectedObject = this;
                pipeline1.UpdateEndPoint(p1);
            }
            if (pipeline2.HeadConnectedObject == pipeJoint)
            {
                pipeline2.HeadConnectedObject = this;
                pipeline2.UpdateStartPoint(p2);
            }
            if (pipeline2.TailConnectedObject == pipeJoint)
            {
                pipeline2.TailConnectedObject = this;
                pipeline2.UpdateEndPoint(p2);
            }
            PipeLine        pipeline3 = new PipeLine(p3, ePoint, false, OwnSolution, true);
            List <PipeLine> lists     = new List <PipeLine>();

            lists.Add(pipeline1);
            lists.Add(pipeline2);
            lists.Add(pipeline3);
            this.SetPipeLines(lists);
            this.GenerateFromConnectedPipes();
            pipeJoint.RemoveEntity();
            return(pipeline3);
        }
Exemple #2
0
 public BaseModel DownGrade(PipeLine line)
 {
     //
     if (this.ConnectedPipes.Contains(line))
     {
         this.RemovePipeLine(line);
         if (this.ConnectedPipes.Count == 2)
         {
             //退化成SimpleJoint 或者 PipeLine
             PipeLine line1 = this.ConnectedPipes[0];
             PipeLine line2 = this.ConnectedPipes[1];
             //退化成新的PipeLine
             if (line1.PipeLineCrossTest(line2) == PipeLine.CrossType.ParallelNoConnect)
             {
                 Point3d   p1, p2;
                 PipeJoint co1, co2;
                 if ((line1.Point(0) - this.CenterPoint).Length > (line1.Point(1) - this.CenterPoint).Length)
                 {
                     p1  = line1.Point(0);
                     co1 = line1.HeadConnectedObject;
                 }
                 else
                 {
                     p1  = line1.Point(1);
                     co1 = line1.TailConnectedObject;
                 }
                 if ((line2.Point(0) - this.CenterPoint).Length > (line2.Point(1) - this.CenterPoint).Length)
                 {
                     p2  = line2.Point(0);
                     co2 = line2.HeadConnectedObject;
                 }
                 else
                 {
                     p2  = line2.Point(1);
                     co2 = line2.TailConnectedObject;
                 }
                 PipeLine pLine = new PipeLine(p1, p2, OwnSolution, true);
                 line1.Delete();
                 line2.Delete();
                 pLine.HeadConnectedObject = co1;
                 if (co1 != null)
                 {
                     co1.RemovePipeLine(line1);
                     co1.AddPipeLine(pLine);
                 }
                 pLine.TailConnectedObject = co2;
                 if (co2 != null)
                 {
                     co2.RemovePipeLine(line2);
                     co2.AddPipeLine(pLine);
                 }
                 this.RemoveEntity();
             }
             else
             {
                 Point3d p1, p2, p3, p4;
                 bool    ht1, ht2; // head or tail, true for head, false for tail
                 if ((line1.Point(0) - this.CenterPoint).Length > (line1.Point(1) - this.CenterPoint).Length)
                 {
                     p1  = line1.Point(0);
                     p3  = line1.Point(1);
                     ht1 = false;
                 }
                 else
                 {
                     p1  = line1.Point(1);
                     p3  = line1.Point(0);
                     ht1 = true;
                 }
                 if ((line2.Point(0) - this.CenterPoint).Length > (line2.Point(1) - this.CenterPoint).Length)
                 {
                     p2  = line2.Point(0);
                     p4  = line2.Point(1);
                     ht2 = false;
                 }
                 else
                 {
                     p2  = line2.Point(1);
                     p4  = line2.Point(0);
                     ht2 = true;
                 }
                 Point3d         intersect       = Utility.Intersect(p1, p3 - p1, p2, p4 - p2);
                 SimplePipeJoint simplePipeJoint = new SimplePipeJoint(p1, intersect, p2, PipeLine.GetScale() / 2, OwnSolution, true);
                 Point3d         p5 = simplePipeJoint.CalculateLastMlineEndPoint();
                 Point3d         p6 = simplePipeJoint.CalculateMlineStartPoint();
                 if (ht1)
                 {
                     line1.UpdateStartPoint(p5);
                     line1.HeadConnectedObject = simplePipeJoint;
                 }
                 else
                 {
                     line1.UpdateEndPoint(p5);
                     line1.TailConnectedObject = simplePipeJoint;
                 }
                 if (ht2)
                 {
                     line2.UpdateStartPoint(p6);
                     line2.HeadConnectedObject = simplePipeJoint;
                 }
                 else
                 {
                     line2.UpdateEndPoint(p6);
                     line2.TailConnectedObject = simplePipeJoint;
                 }
                 simplePipeJoint.AddPipeLine(line1);
                 simplePipeJoint.AddPipeLine(line2);
                 this.RemoveEntity();
             }
         }
         else
         {
             this.GenerateFromConnectedPipes();
         }
     }
     return(null);
 }
        /// <summary>
        /// 管道相交测试
        /// </summary>
        /// <param name="pipeLine">测试管道</param>
        /// <param name="isFirst">相交测试是一个递归的过程,在一层递归里面PipeLine并没有被实际创建,而是在测试结束后才创建,下面的递归
        /// 层,测试的管道都是已经被创建了的</param>
        /// <returns></returns>
        public Point3d?PipeLineCrossTest(PipeLine pipeLine)
        {
            Point3d?res;
            Dictionary <ObjectId, PipeLine> copyPipelines = new Dictionary <ObjectId, PipeLine>();

            foreach (var item in PipeLines)
            {
                copyPipelines.Add(item.Key, item.Value);
            }

            //和管道测试相交
            foreach (var item in copyPipelines)
            {
                PipeLine cItem = (PipeLine)item.Value;
                if (cItem == pipeLine)
                {
                    continue;
                }
                PipeLine.CrossType type = cItem.PipeLineCrossTest(pipeLine);
                if (type == PipeLine.CrossType.CrossNone)
                {
                    continue;
                }
                else if (type == PipeLine.CrossType.ParallelHead)
                {
                    Point3d p1 = pipeLine.Point(0);
                    Point3d p2 = pipeLine.Point(1);
                    Point3d p3;
                    bool    result = false;
                    if ((p1 - cItem.Point(0)).Length < (p2 - cItem.Point(0)).Length)
                    {
                        result = false;
                        p3     = p2;
                    }
                    else
                    {
                        result = true;
                        p3     = p1;
                    }
                    Vector3d v  = cItem.Point(0) - cItem.Point(1);
                    Vector3d v1 = p3 - cItem.Point(0);
                    Point3d  p  = cItem.Point(0) + v1.DotProduct(v.GetNormal()) * v.GetNormal();
                    //
                    pipeLine = new PipeLine(p, cItem.Point(1), false, this);
                    pipeLine.TailConnectedObject = cItem.TailConnectedObject;
                    if (pipeLine.TailConnectedObject != null)
                    {
                        pipeLine.TailConnectedObject.RemovePipeLine(cItem);
                        pipeLine.TailConnectedObject.AddPipeLine(pipeLine);
                    }
                    cItem.Delete();
                    //递归调用

                    res = PipeLineCrossTest(pipeLine);
                    if (result)
                    {
                        return(null);
                    }
                    else
                    {
                        return(res);
                    }
                }
                else if (type == PipeLine.CrossType.ParallelTail)
                {
                    Point3d p1 = pipeLine.Point(0);
                    Point3d p2 = pipeLine.Point(1);
                    Point3d p3;
                    bool    result;
                    if ((p1 - cItem.Point(1)).Length < (p2 - cItem.Point(1)).Length)
                    {
                        result = false;
                        p3     = p2;
                    }
                    else
                    {
                        result = true;
                        p3     = p1;
                    }
                    Vector3d v  = cItem.Point(1) - cItem.Point(0);
                    Vector3d v1 = p3 - cItem.Point(1);
                    Point3d  p  = cItem.Point(1) + v1.DotProduct(v.GetNormal()) * v.GetNormal();
                    //
                    pipeLine = new PipeLine(cItem.Point(0), p, false, this);
                    pipeLine.HeadConnectedObject = cItem.HeadConnectedObject;
                    if (pipeLine.HeadConnectedObject != null)
                    {
                        pipeLine.HeadConnectedObject.RemovePipeLine(cItem);
                        pipeLine.HeadConnectedObject.AddPipeLine(pipeLine);
                    }
                    cItem.Delete();
                    //递归调用
                    res = PipeLineCrossTest(pipeLine);
                    if (result)
                    {
                        return(null);
                    }
                    else
                    {
                        return(res);
                    }
                }
                else if (type == PipeLine.CrossType.NonParallelHead)
                {
                    Point3d p1 = pipeLine.Point(0);
                    Point3d p2 = pipeLine.Point(1);
                    Point3d p3;
                    bool    result;
                    if ((p1 - cItem.Point(0)).Length < (p2 - cItem.Point(0)).Length)
                    {
                        result = false;
                        p3     = p2;
                    }
                    else
                    {
                        result = true;
                        p3     = p1;
                    }
                    SimplePipeJoint simplePipeJoint = new SimplePipeJoint(cItem.Point(1), cItem.Point(0), p3, PipeLine.GetScale() / 2, this, true);
                    cItem.UpdateStartPoint(simplePipeJoint.CalculateLastMlineEndPoint());
                    Point3d startPoint = simplePipeJoint.CalculateMlineStartPoint();
                    simplePipeJoint.AddPipeLine(cItem);
                    PipeLine newLine = new PipeLine(p3, startPoint, false, this);
                    simplePipeJoint.AddPipeLine(newLine);
                    cItem.HeadConnectedObject   = simplePipeJoint;
                    newLine.TailConnectedObject = simplePipeJoint;
                    if (pipeLine.HeadConnectedObject != null)
                    {
                        pipeLine.HeadConnectedObject.RemovePipeLine(pipeLine);
                        pipeLine.HeadConnectedObject.AddPipeLine(newLine);
                        newLine.HeadConnectedObject = pipeLine.HeadConnectedObject;
                    }
                    //递归调用
                    res = PipeLineCrossTest(newLine);
                    if (result)
                    {
                        return(null);
                    }
                    else
                    {
                        return(res);
                    }
                }
                else if (type == PipeLine.CrossType.NonParallelTail)
                {
                    Point3d p1 = pipeLine.Point(0);
                    Point3d p2 = pipeLine.Point(1);
                    Point3d p3;
                    bool    result;
                    if ((p1 - cItem.Point(1)).Length < (p2 - cItem.Point(1)).Length)
                    {
                        result = false;
                        p3     = p2;
                    }
                    else
                    {
                        result = true;
                        p3     = p1;
                    }
                    SimplePipeJoint simplePipeJoint = new SimplePipeJoint(cItem.Point(0), cItem.Point(1), p3, PipeLine.GetScale() / 2, this, true);
                    cItem.UpdateEndPoint(simplePipeJoint.CalculateLastMlineEndPoint());
                    cItem.TailConnectedObject = simplePipeJoint;
                    Point3d startPoint = simplePipeJoint.CalculateMlineStartPoint();
                    simplePipeJoint.AddPipeLine(cItem);
                    PipeLine newLine = new PipeLine(startPoint, p3, false, this);
                    simplePipeJoint.AddPipeLine(newLine);
                    newLine.HeadConnectedObject = simplePipeJoint;
                    if (pipeLine.TailConnectedObject != null)
                    {
                        pipeLine.TailConnectedObject.RemovePipeLine(pipeLine);
                        pipeLine.TailConnectedObject.AddPipeLine(newLine);
                        newLine.TailConnectedObject = pipeLine.TailConnectedObject;
                    }
                    res = PipeLineCrossTest(newLine);
                    if (result)
                    {
                        return(null);
                    }
                    else
                    {
                        return(res);
                    }
                }
                else if (type == PipeLine.CrossType.CrossHead)
                {
                    MultiPipeJoint mj = new MultiPipeJoint(this, true);
                    List <Point3d> ps = mj.GenerateFromCrossPipe(cItem, pipeLine.Point(0), pipeLine.Point(1), PipeLine.GetScale() / 2);
                    PipeLine       p1 = new PipeLine(cItem.Point(0), ps[0], this, true);
                    PipeLine       p2 = new PipeLine(ps[1], cItem.Point(1), this, true);
                    //
                    if (cItem.HeadConnectedObject != null)
                    {
                        cItem.HeadConnectedObject.RemovePipeLine(cItem);
                        cItem.HeadConnectedObject.AddPipeLine(p1);
                    }
                    if (cItem.TailConnectedObject != null)
                    {
                        cItem.TailConnectedObject.RemovePipeLine(cItem);
                        cItem.TailConnectedObject.AddPipeLine(p2);
                    }
                    p1.HeadConnectedObject = cItem.HeadConnectedObject;
                    p1.TailConnectedObject = mj;
                    p2.HeadConnectedObject = mj;
                    p2.TailConnectedObject = cItem.TailConnectedObject;

                    Point3d startPoint = ps[2];
                    cItem.Delete();

                    PipeLine pLine = new PipeLine(startPoint, pipeLine.Point(1), false, this);
                    pLine.HeadConnectedObject = mj;
                    if (pipeLine.TailConnectedObject != null)
                    {
                        pipeLine.TailConnectedObject.RemovePipeLine(pipeLine);
                        pipeLine.TailConnectedObject.AddPipeLine(pLine);
                        pLine.TailConnectedObject = pipeLine.TailConnectedObject;
                    }
                    mj.AddPipeLine(p1);
                    mj.AddPipeLine(p2);
                    mj.AddPipeLine(pLine);

                    res = PipeLineCrossTest(pLine);
                    return(res);
                }
                else if (type == PipeLine.CrossType.CrossTail)
                {
                    //
                    MultiPipeJoint mj = new MultiPipeJoint(this, true);
                    List <Point3d> ps = mj.GenerateFromCrossPipe(cItem, pipeLine.Point(1), pipeLine.Point(0), PipeLine.GetScale() / 2);
                    PipeLine       p1 = new PipeLine(cItem.Point(0), ps[0], this, true);
                    PipeLine       p2 = new PipeLine(ps[1], cItem.Point(1), this, true);
                    //
                    if (cItem.HeadConnectedObject != null)
                    {
                        cItem.HeadConnectedObject.RemovePipeLine(cItem);
                        cItem.HeadConnectedObject.AddPipeLine(p1);
                    }
                    if (cItem.TailConnectedObject != null)
                    {
                        cItem.TailConnectedObject.RemovePipeLine(cItem);
                        cItem.TailConnectedObject.AddPipeLine(p2);
                    }
                    p1.HeadConnectedObject = cItem.HeadConnectedObject;
                    p1.TailConnectedObject = mj;
                    p2.HeadConnectedObject = mj;
                    p2.TailConnectedObject = cItem.TailConnectedObject;
                    Point3d startPoint = ps[2];
                    cItem.Delete();
                    PipeLine pLine = new PipeLine(pipeLine.Point(0), startPoint, false, this);
                    pLine.TailConnectedObject = mj;
                    if (pipeLine.HeadConnectedObject != null)
                    {
                        pipeLine.HeadConnectedObject.RemovePipeLine(pipeLine);
                        pipeLine.HeadConnectedObject.AddPipeLine(pLine);
                        pLine.HeadConnectedObject = pipeLine.HeadConnectedObject;
                    }
                    mj.AddPipeLine(p1);
                    mj.AddPipeLine(p2);
                    mj.AddPipeLine(pLine);
                    PipeLineCrossTest(pLine);
                    return(mj.CenterPoint);
                }
                else if (type == PipeLine.CrossType.CrossOver)
                {
                    MultiPipeJoint mj = new MultiPipeJoint(this, true);
                    List <Point3d> ps = mj.GenerateFromCrossPipe(cItem, pipeLine.Point(1), pipeLine.Point(0), PipeLine.GetScale() / 2);
                    PipeLine       p1 = new PipeLine(cItem.Point(0), ps[0], this, true);
                    PipeLine       p2 = new PipeLine(ps[1], cItem.Point(1), this, true);
                    if (cItem.HeadConnectedObject != null)
                    {
                        cItem.HeadConnectedObject.RemovePipeLine(cItem);
                        cItem.HeadConnectedObject.AddPipeLine(p1);
                    }
                    if (cItem.TailConnectedObject != null)
                    {
                        cItem.TailConnectedObject.RemovePipeLine(cItem);
                        cItem.TailConnectedObject.AddPipeLine(p2);
                    }

                    p1.HeadConnectedObject = cItem.HeadConnectedObject;
                    p1.TailConnectedObject = mj;
                    p2.HeadConnectedObject = mj;
                    p2.TailConnectedObject = cItem.TailConnectedObject;

                    Point3d startPoint = ps[2];
                    cItem.Delete();

                    PipeLine pLine = new PipeLine(pipeLine.Point(0), startPoint, false, this);
                    pLine.TailConnectedObject = mj;
                    if (pipeLine.HeadConnectedObject != null)
                    {
                        pipeLine.HeadConnectedObject.RemovePipeLine(pipeLine);
                        pipeLine.HeadConnectedObject.AddPipeLine(pLine);
                        pLine.HeadConnectedObject = pipeLine.HeadConnectedObject;
                    }
                    mj.AddPipeLine(p1);
                    mj.AddPipeLine(p2);
                    mj.AddPipeLine(pLine);
                    PipeLineCrossTest(pLine);
                    //插入新的点
                    PipeLine se = mj.UpdateMultiJoint(pipeLine.Point(1));
                    se.HeadConnectedObject = mj;
                    if (pipeLine.TailConnectedObject != null)
                    {
                        pipeLine.TailConnectedObject.RemovePipeLine(pipeLine);
                        pipeLine.TailConnectedObject.AddPipeLine(se);
                        se.TailConnectedObject = pipeLine.TailConnectedObject;
                    }
                    res = PipeLineCrossTest(se);
                    return(res);
                }
            }
            foreach (var item in SimplePipeJoints)
            {
                SimplePipeJoint pItem = (SimplePipeJoint)item.Value;
                if (pItem.PointInJoint(pipeLine.Point(0)) && !pItem.ConnectedPipes.Contains(pipeLine))
                {
                    MultiPipeJoint mpj = new MultiPipeJoint(this, true);
                    PipeLine       ps  = mpj.GenerateFromSimpleJoint(pItem, pipeLine.Point(1), PipeLine.GetScale() / 2);
                    ps.HeadConnectedObject = mpj;
                    res = PipeLineCrossTest(ps);
                    return(res);
                }
                if (pItem.PointInJoint(pipeLine.Point(1)) && !pItem.ConnectedPipes.Contains(pipeLine))
                {
                    MultiPipeJoint mpj = new MultiPipeJoint(this, true);
                    PipeLine       ps  = mpj.GenerateFromSimpleJoint(pItem, pipeLine.Point(0), PipeLine.GetScale() / 2);
                    ps.TailConnectedObject = mpj;
                    res = PipeLineCrossTest(ps);
                    return(null);
                }
            }
            foreach (var item in MultiPipeJoints)
            {
                MultiPipeJoint pItem = (MultiPipeJoint)item.Value;
                if (pItem.PointInJoint(pipeLine.Point(0)) && !pItem.ConnectedPipes.Contains(pipeLine))
                {
                    PipeLine se = pItem.UpdateMultiJoint(pipeLine.Point(1));
                    se.HeadConnectedObject = pItem;
                    res = PipeLineCrossTest(se);
                    return(res);
                }
                if (pItem.PointInJoint(pipeLine.Point(1)) && !pItem.ConnectedPipes.Contains(pipeLine))
                {
                    PipeLine se = pItem.UpdateMultiJoint(pipeLine.Point(0));
                    se.HeadConnectedObject = pItem;
                    res = PipeLineCrossTest(se);
                    return(null);
                }
            }
            pipeLine.SaveEntity();
            return(pipeLine.Point(1));
        }