static bool ContainsAsSpan(Line line, Line spanCandidate) { SpanningLine span = spanCandidate as SpanningLine; bool result = (span != null) && span.Blocks.Contains(line.Id); return(result); }
// create the extension of the given line RectangleF GetRectangle(Line line) { //Console.WriteLine("retrieving rect for {0}", line.Id); if (basicLines.ContainsKey(line)) { return(basicLines[line]); } else if (spanningLines.ContainsKey(line)) { return(spanningLines[line]); } RectangleF result = new RectangleF(0, 0, ItemSize, ItemSize); if (line is RelativeLine) { BasicLine thisLine = line as RelativeLine; Line relativeTo = formation.Lines[(int)(line as RelativeLine).RelativeTo]; RectangleF relationRect = GetRectangle(relativeTo); result.X = (relationRect.X + thisLine.X - Math.Sign(thisLine.X) * ItemSize); //if (thisLine.Y == 0) { result.X += (relationRect.Width - ItemSize) / 2; //} result.Y = (relationRect.Y + thisLine.Y - Math.Sign(thisLine.Y) * ItemSize); //if (thisLine.X == 0) { result.Y += (relationRect.Height - ItemSize) / 2; //} basicLines.Add(line, result); } else if (line is SpanningLine) { SpanningLine sl = line as SpanningLine; formation.Lines.ForEach(l => { if (sl.Blocks.Contains(l.Id)) { result = RectangleF.Union(result, GetRectangle(l)); } }); spanningLines.Add(line, result); //result = new Rectangle(minX, minY, Math.Abs(maxX - minX), Math.Abs(maxY - minY)); } else { BasicLine baseLine = line as BasicLine; result = new RectangleF(baseLine.X, baseLine.Y, ItemSize, ItemSize); basicLines.Add(line, result); } //Console.WriteLine("rect for {1} is {0}", result, line.Id); return(result); }
Line ReadLine(BinaryReader reader) { Line line; int id = reader.ReadInt32(); LineType lineType = (LineType)reader.ReadUInt32(); //Console.WriteLine("reading line type {0} at {1}", lineType, reader.BaseStream.Position); if (lineType == LineType.spanning) { line = new SpanningLine { Blocks = ReadList <int>(reader, delegate(BinaryReader r) { return(r.ReadInt32()); }) }; } else if (lineType == LineType.absolute || lineType == LineType.relative) { BasicLine basicLine = (lineType == LineType.absolute) ? new BasicLine() : new RelativeLine(); basicLine.Priority = reader.ReadSingle(); if (lineType == LineType.relative) { (basicLine as RelativeLine).RelativeTo = reader.ReadUInt32(); } basicLine.Shape = reader.ReadInt32(); basicLine.Spacing = reader.ReadSingle(); basicLine.Crescent_Y_Offset = reader.ReadSingle(); basicLine.X = reader.ReadSingle(); basicLine.Y = reader.ReadSingle(); basicLine.MinThreshold = reader.ReadInt32(); basicLine.MaxThreshold = reader.ReadInt32(); basicLine.PriorityClassPairs = ReadList <PriorityClassPair>(reader, ReadPriorityClassPair); line = basicLine; } else { throw new InvalidDataException("unknown line type " + lineType); } line.Id = id; return(line); }
private void addUnitPriorityButton_Click(object sender, EventArgs e) { Console.WriteLine("adding priority"); if (SelectedLine is BasicLine) { PriorityClassPair pair = PromptPriorityClassPair(); if (pair != null) { unitPriorityList.Items.Add(pair); (SelectedLine as BasicLine).PriorityClassPairs.Add(pair); SetModified(true); } } else if (SelectedLine is SpanningLine) { InputBox box = new InputBox(); SpanningLine spanningLine = SelectedLine as SpanningLine; if (box.ShowDialog() == DialogResult.OK) { int add; if (int.TryParse(box.Input, out add)) { if (!spanningLine.Blocks.Contains(add)) { spanningLine.Blocks.Add(add); unitPriorityList.Items.Add(add); Modified = true; } } else { MessageBox.Show("Invalid input"); return; } } } }