public int Distance(JamRange12 range) { if (range.StartIndex > EndIndex) return range.StartIndex - EndIndex-1; //在後 else return -(this.StartIndex - range.EndIndex-1); //在前 }
public bool Merge( JamRange12 range) { int distance=Distance(range); //相鄰超過兩座以上 if (Math.Abs(distance)>=2) return false; //相鄰一座 if (distance == 1) { VDDeviceWrapper vd = (VDDeviceWrapper)range.devlist[0]; if (((VDDeviceWrapper)vd.PreDevice).jamLevel < 2) return false; } if (distance == -1) { VDDeviceWrapper vd = (VDDeviceWrapper)this.devlist[0]; if (((VDDeviceWrapper)vd.PreDevice).jamLevel < 2) return false; } foreach (VDDeviceWrapper dev in range.devlist) this.devlist.Add(dev); this.devlist.Sort(); range.DelMark = true; return true; }
public JamRange12[] Split() { //chek 22 for (int i = 1; i < devlist.Count - 1; i++) { VDDeviceWrapper vd =devlist[i] as VDDeviceWrapper; if ((vd.jamLevel == 2 && ((VDDeviceWrapper)vd.NextDevice).jamLevel == 2) || vd.jamLevel < 2) { JamRange12[] splitrang = new JamRange12[2]; splitrang[0] = new JamRange12(devlist[0] as VDDeviceWrapper); splitrang[1]=new JamRange12(devlist[devlist.Count-1] as VDDeviceWrapper); for (int j = 1; j < i; j++) splitrang[0].Merge(new JamRange12(devlist[j] as VDDeviceWrapper)); for (int j = (vd.jamLevel==2)?i + 2:i+1; j < devlist.Count-1; j++) splitrang[1].Merge(new JamRange12(devlist[j] as VDDeviceWrapper)); return splitrang; } } return null; }
void CheckDegree1And2LineJam(string key) { ArrayList tmp = new ArrayList(); ArrayList vdlist = (ArrayList)lines[key]; ArrayList rangelist = (ArrayList)this.lineDegree2and1JamRanges[key]; ArrayList rmlst = new ArrayList(); //check 已存在的1,2級事件是否 degree change foreach (JamRange12 r in rangelist) { if (r.CheckDegre1and2eChange()) { if (r.getDegree() == 1 || r.getDegree() == 2) { r.invokeDegreeChange(); } else if (r.getDegree() == 0 || r.getDegree() == 3 || r.getDegree()==-1) { r.invokeStop(); // rangelist.Remove(r); rmlst.Add(r); } } //if (r.Shrink()) // r.invokeRangeChange(); //else if (r.DelMark) // rmlst.Add(r); //event here } foreach( JamRange12 r in rmlst) rangelist.Remove(r); rmlst.Clear(); // check new JamEvent foreach (VDDeviceWrapper vd in vdlist) { if(vd.jamLevel==2 || vd.jamLevel==1) { bool found = false; foreach (JamRange12 r in rangelist) { if (r.DeviceName == vd.deviceName) { found = true; break; } } // 加入新事件 if (!found) { JamRange12 range=new JamRange12(vd); rangelist.Add(range); Program.matrix.event_mgr.AddEvent(range); } } } }