ArrayList Search(string devType, I_Positionable p, int totalSeg,int segid,bool IsBranch) { System.Collections.ArrayList list=new ArrayList(); if ( p==null || segid>totalSeg ) return list; ArrayList tmplst = null, branchlst1 = null, branchlst2 = null; if (p.getDevType() == "C" || p.getDevType() == "I") { tmplst = Search(devType, p.getPrevDev(), totalSeg, segid + 1,IsBranch); if (p.getDevType() == "C" && IsBranch) { branchlst1 = Search(devType, ((InterSection)p).branch1, totalSeg, segid , false); branchlst2 = Search(devType, ((InterSection)p).branch2, totalSeg, segid, false); } } else { tmplst = Search(devType, p.getPrevDev(), totalSeg, segid,IsBranch); } if (p.getDevType() == devType) { // will try catch here list.Add(new FetchDeviceData(p.getDevName(), segid, p.getLineID(), p.getDirection(), p.getMileage(), Program.matrix.line_mgr[p.getLineID()].getSectionByMile(p.getDirection(), p.getMileage()).maxSpeed, Program.matrix.line_mgr[p.getLineID()].getSectionByMile(p.getDirection(), p.getMileage()).minSpeed)); } foreach (FetchDeviceData fdata in tmplst) list.Add(fdata); if(branchlst1!=null) foreach (FetchDeviceData fdata in branchlst1) list.Add(fdata); if (branchlst2 != null) foreach (FetchDeviceData fdata in branchlst2) list.Add(fdata); return list; }
ArrayList Search(string devType, I_Positionable p,I_Positionable parent, int totalSeg,int segid,bool IsBranch,int branchcnt) { System.Collections.ArrayList list=new ArrayList(); if ( p==null || segid>totalSeg || branchcnt>3) return list; ArrayList tmplst = null, branchlst1 = null, branchlst2 = null; if (p.getDevType() == "C" || p.getDevType() == "I") { tmplst = Search(devType, p.getPrevDev(),p, totalSeg, segid + 1,IsBranch,branchcnt); if (p.getDevType() == "C" && IsBranch) { // branchlst1 = Search(devType, ((InterSection)p).branch1, totalSeg, segid , false); // branchlst2 = Search(devType, ((InterSection)p).branch2, totalSeg, segid, false); if (parent==null || ((InterSection)p).branch1 != parent && ((InterSection)p).branch2 != parent) // 防止指回 { if (segid == 0 && branchcnt == 0) //近 { branchlst1 = Search(devType, ((InterSection)p).branch1, p, segid + 2, segid, IsBranch, branchcnt + 1); branchlst2 = Search(devType, ((InterSection)p).branch2, p, segid + 2, segid, IsBranch, branchcnt + 1); } else if (segid == 1 && branchcnt == 0) //中 { branchlst1 = Search(devType, ((InterSection)p).branch1, p, segid + 1, segid, IsBranch, branchcnt + 1); branchlst2 = Search(devType, ((InterSection)p).branch2, p, segid + 1, segid, IsBranch, branchcnt + 1); } else if (segid > 1 && branchcnt == 0) //遠 { branchlst1 = Search(devType, ((InterSection)p).branch1, p, segid + 1, segid, IsBranch, branchcnt + 1); branchlst2 = Search(devType, ((InterSection)p).branch2, p, segid + 1, segid, IsBranch, branchcnt + 1); } else { branchlst1 = Search(devType, ((InterSection)p).branch1, p, totalSeg, segid, IsBranch, branchcnt + 1); branchlst2 = Search(devType, ((InterSection)p).branch2, p, totalSeg, segid, IsBranch, branchcnt + 1); } } } } else { tmplst = Search(devType, p.getPrevDev(),p, totalSeg, segid,IsBranch,branchcnt); } if (p.getDevType() == devType) { // will try catch here list.Add(new FetchDeviceData(p.getDevName(), segid, p.getLineID(), p.getDirection(), p.getMileage(), Program.matrix.line_mgr[p.getLineID()].getSectionByMile(p.getDirection(), p.getMileage()).maxSpeed, Program.matrix.line_mgr[p.getLineID()].getSectionByMile(p.getDirection(), p.getMileage()).minSpeed, devType)); } foreach (FetchDeviceData fdata in tmplst) list.Add(fdata); if(branchlst1!=null) foreach (FetchDeviceData fdata in branchlst1) list.Add(fdata); if (branchlst2 != null) foreach (FetchDeviceData fdata in branchlst2) list.Add(fdata); return list; }