Exemplo n.º 1
0
        public LcLink LinkTo(string lptname, Vector3 v, string lname = "")
        {
            var lp0 = anchorpt;

            if (lp0 == null)
            {
                throw new UnityException("Anchorpt null");
            }
            lptname = gm.addprefix(lptname);
            v       = gm.modv(v);
            var lp1 = GetNewNode(lptname, v);

            if (lname == "")
            {
                lname = lp0.name + ":" + lptname;
            }
            else
            {
                lname = gm.addprefix(lname);
            }
            if (linkdict.ContainsKey(lname))
            {
                throw new UnityException("LinkTo: Duplicate Link name:" + lname);
            }
            linknamelist.Add(lname);

            var lnk = new LcLink(this, lname, lp0, lp1);

            linkdict.Add(lname, lnk);
            //lklistlist.Add(lnk);
            anchorpt = lp1;
            return(lnk);
        }
Exemplo n.º 2
0
        public LcLink AddLinkByNodeName(string lp1name, string lp2name, string lname = "")
        {
            lp1name = gm.addprefix(lp1name);
            lp2name = gm.addprefix(lp2name);
            verifyNodeExists("AddLink", lp1name);
            verifyNodeExists("AddLink", lp2name);
            var lp1 = nodedict[lp1name];
            var lp2 = nodedict[lp2name];

            if (lname == "")
            {
                lname = gm.addprefix(lp1.name + ":" + lp2.name);
            }
            else
            {
                lname = gm.addprefix(lname);
            }

            if (linkdict.ContainsKey(lname))
            {
                throw new UnityException("AddLinkByNodeName: Duplicate Link name:" + lname);
            }
            linknamelist.Add(lname);
            var lnk = new LcLink(this, lname, lp1, lp2);

            linkdict.Add(lname, lnk);
            //lklistlist.Add(lnk);
            return(lnk);
        }
Exemplo n.º 3
0
 public Weg(LcLink link, LcNode tonode, LcNode frnode)
 {
     this.link     = link;
     this.toNode   = tonode;
     this.frNode   = frnode;
     this.distance = Vector3.Distance(frnode.pt, tonode.pt);
 }
Exemplo n.º 4
0
        public LcLink AddLink(string lname, LcNode lp1, LcNode lp2)
        {
            lname = gm.addprefix(lname);
            if (linkdict.ContainsKey(lname))
            {
                throw new UnityException("AddLink: Duplicate Link name:" + lname);
            }
            linknamelist.Add(lname);
            var lnk = new LcLink(this, lname, lp1, lp2);

            linkdict.Add(lname, lnk);
            //lklistlist.Add(lnk);
            return(lnk);
        }
Exemplo n.º 5
0
        public LcNode PunchNewLinkPt(LcLink lnk, Vector3 pt, string newptname = "", string newlinkrootname = "", bool deleteparentlink = false, bool alwayspunch = false)
        {
            if (!alwayspunch)
            {
                // we don't punch a new link point if we are close enough to one of the end points
                // 5e-2 is 5 cm
                if (Vector3.Distance(pt, lnk.node1.pt) < 5e-2)
                {
                    //  GraphUtil.Log("Punched to lp1:"+lnk.lp1.pt);
                    return(lnk.node1);
                }
                if (Vector3.Distance(pt, lnk.node2.pt) < 5e-2)
                {
                    //  GraphUtil.Log("Punched to lp2:" + lnk.lp2.pt);
                    return(lnk.node2);
                }
            }
            if (newptname == "")
            {
                newptname = "tmp-x-" + newnodecount;
            }
            newnodecount += 1;
            pt            = gm.unmodv(pt);
            //GraphUtil.Log("Adding point:" + pt);
            var newlpt       = AddNode(newptname, pt);
            var newlinkname0 = "";
            var newlinkname1 = "";

            if (newlinkrootname != "")
            {
                newlinkname0 = newlinkrootname + "0";
                newlinkname1 = newlinkrootname + "1";
            }
            else
            {
                newlinkname0 = lnk.name + "0";
                newlinkname1 = lnk.name + "1";
            }
            AddLink(newlinkname0, newlpt, lnk.node1);
            //GraphUtil.Log("Adding lnk:" + newlinkname0);
            AddLink(newlinkname1, newlpt, lnk.node2);
            //GraphUtil.Log("Adding lnk:" + newlinkname1);
            if (deleteparentlink)
            {
                //GraphUtil.Log("Deleting lnk:" + lnk.name);
                DelLink(lnk.name);
            }
            return(newlpt);
        }
Exemplo n.º 6
0
        void ApdNewLinkByName(LcLink link, LinkUse usetype)
        {
            var frname = link.node1.name;

            if (link.node1spec != "")
            {
                frname = link.node1spec;
            }
            var tuname = link.node2.name;

            if (link.node2spec != "")
            {
                tuname = link.node2spec;
            }
            var s = indent + "grc.AddLinkByNodeName( " + q(frname) + "," + q(tuname) + ", LinkUse." + usetype.ToString() + apd;

            lines.Add(s);
            nlinkbyname++;
        }
Exemplo n.º 7
0
        public LcLink FindClosestLinkOnLineCloudFiltered(string filter, Vector3 pt, bool deb = false)
        {
            if (deb)
            {
                GraphUtil.Log("FCLOLCF filter:" + filter + " pt:" + pt);
            }
            var    rpt     = Vector3.zero;
            LcLink rlnk    = null;
            float  mindist = 9e30f;

            foreach (var lnkname in linknamelist)
            {
                var lnk = GetLink(lnkname);
                if (filter == "" || lnk.name.IndexOf(filter) == 0)
                {
                    var npt  = lnk.FindClosestPointOnLink(pt);
                    var dist = Vector3.Distance(pt, npt);
                    if (dist < mindist)
                    {
                        rlnk    = lnk;
                        rpt     = npt;
                        mindist = dist;
                        if (deb)
                        {
                            var lamb = lnk.FindClosestLamb(pt);
                            GraphUtil.Log("    lnk:" + lnk.name + " npt:" + npt + " dist:" + dist + " lamb:" + lamb);
                            GraphUtil.Log("    lnk.p1:" + lnk.node1.pt + " p2:" + lnk.node2.pt);
                        }
                    }
                }
            }
            if (deb)
            {
                GraphUtil.Log("FCLOLCF found:" + rlnk.name);
            }
            return(rlnk);
        }