public void ContextMenuAddChild(object sender, RoutedEventArgs e) { if (!(sender is MenuItem)) { return; } string guid = ((MenuItem)sender).Name.Substring(1, ((MenuItem)sender).Name.Length - 1).Replace("_", "-"); foreach (var umlElement in elements) { if (umlElement is UMLClassBox && ((UMLClassBox)umlElement).getGuid() == guid) { UMLClassBox f = umlElement as UMLClassBox; Point s = f.GetCenterPoint(); UMLClassBox n = new UMLClassBox("NewChildClass", UMLClassBox.BoxType.Class, new Point(s.X + 160, s.Y), classes); n.draw(drawCanvas); n.initMenu(this); DependencyArrow dependency = new DependencyArrow(n, f, (f.getType() == UMLClassBox.BoxType.Class)? DependencyArrow.Tips.DerivArrow: DependencyArrow.Tips.ImplementationArrow); dependency.draw(drawCanvas); elements.Add(n); elements.Add(dependency); return; } } }
// 依存関係表示用のブラシ,ペンを作成 private void MakeDependencyArrow() { dependencyArrows = new List <DependencyArrow>(); Color[] colorSet = { Color.Crimson, Color.Blue, Color.Green, Color.Yellow, }; foreach (Color color in colorSet) { DependencyArrow arrow = new DependencyArrow(color, 1.0f); dependencyArrows.Add(arrow); } }
private void Canvas_MouseUp(object sender, MouseButtonEventArgs e) { Point now = e.GetPosition((UIElement)sender); if (picked == State.ClassBox || picked == State.InterfaceBox) { drawCanvas.Children.Remove(rectangle); now = new Point(now.X - rectangle.Width / 2, now.Y - rectangle.Height / 2); UMLClassBox box = new UMLClassBox("SomeClass", (picked == State.ClassBox)? UMLClassBox.BoxType.Class: UMLClassBox.BoxType.Interface, now, classes); box.initMenu(this); box.draw(drawCanvas); elements.Add(box); setMode(State.Editing); } else if (picked == State.Editing && !isMoving && e.ChangedButton == MouseButton.Left && e.ChangedButton != MouseButton.Right) { UMLElement g = getPickedElement(now); if (g != null) { g.setPicked(!g.getPicked()); return; } } else if (picked != State.Editing) { if (!doubleClick) { doubleClick = true; fblock = getPickedElement(now); } else { DependencyArrow.Tips s; s = convertTip(); doubleClick = false; DependencyArrow line = new DependencyArrow(fblock, getPickedElement(now), s); line.draw(drawCanvas); elements.Add(line); setMode(State.Editing); } } isMoving = false; }
public Storage(Stream context, EventBridge bridge, List <string> classes) { BinaryFormatter formatter = new BinaryFormatter(); sList = (List <T>)formatter.Deserialize(context); foreach (var v in sList) { if (!(v is DependencyArrow)) { (v as UMLClassBox).initMenu(bridge); (v as UMLClassBox).beforeLoadSets(classes); continue; } DependencyArrow arrow = v as DependencyArrow; UMLClassBox f = null; UMLClassBox s = null; foreach (var block in sList) { if (!(block is UMLClassBox)) { continue; } if ((block as UMLClassBox).getGuid() == arrow.getFGUID()) { f = block as UMLClassBox; } else if ((block as UMLClassBox).getGuid() == arrow.getSGUID()) { s = block as UMLClassBox; } if (f != null && s != null) { break; } } arrow.setDependencyBeforeLoad(f, s); } }
private void DrawDependencyArrow(Graphics g, ulong prodid, ulong consid, int type) { Insn prodinsn = GetInsn(prodid); Insn consinsn = GetInsn(consid); if (prodinsn == null || consinsn == null) { return; } float prodBaseY = coordinateSystem.YAtInsnId(prodid) + CellMarginHeight + coordinateSystem.Cell.Height * 0.5f; float consBaseY = coordinateSystem.YAtInsnId(consid) + CellMarginHeight + coordinateSystem.Cell.Height * 0.5f; float prody = prodBaseY; float consy = consBaseY; if (type >= dependencyArrows.Count) { type = 0; } DependencyArrow arrow = dependencyArrows[type]; Brush dependencyArrowBrush = arrow.brush; Pen dependencyArrowPen = arrow.pen; if (currentViewSetting.DrawDependencyLeftCurve && DrawDependencyLeftCurve) { float prodx = coordinateSystem.XAtCycle(prodinsn.StartCycle); float consx = coordinateSystem.XAtCycle(consinsn.StartCycle); float dy = consy - prody; float left = Math.Min(prodx, consx) - coordinateSystem.Grid.Width; PointF[] pts = new PointF[4]; pts[0] = new PointF(prodx, prody); pts[1] = new PointF(left, prody); pts[2] = new PointF(left, consy); pts[3] = new PointF(consx, consy); DrawArrowhead(g, dependencyArrowBrush, pts[3], new PointF(currentViewSetting.DependencyArrowheadLength, 0), 0.8f); g.DrawBezier(dependencyArrowPen, pts[0], pts[1], pts[2], pts[3]); } if ((currentViewSetting.DrawDependencyInsideCurve && DrawDependencyInsideCurve) || (currentViewSetting.DrawDependencyInsideLine && DrawDependencyInsideLine) ) { float prodx = 0; // prodx, consyが初期化されていないと文句を言われるので…… float consx = 0; // Find an execution stage from a producer and // decide the beginning point of a dependency line. { bool found = false; int prodLane = 0; float prodLaneY = prodBaseY; foreach (var segment in prodinsn.StageSegments) { if (prodLane != 0 && config.DrawInSeparateLane[prodLane]) { prodLaneY += coordinateSystem.Cell.Height; prody = prodLaneY; } else { prody = prodBaseY; } List <Insn.Stage> prodStages = segment; // 0 is a normal stage segment. for (int i = prodStages.Count - 1; i >= 0; i--) { Insn.Stage stage = prodStages[i]; if (IsExecStageId(prodLane, stage.Id)) { prodx = coordinateSystem.XAtCycle(prodinsn.StartCycle + stage.EndRelCycle) - coordinateSystem.Grid.Width * 0.2f; if (stage.Length == 0) { prodx += coordinateSystem.Grid.Width; } found = true; break; } } if (found) { break; } prodLane++; } if (!found) { return; } } // Find an execution stage from a consumer. // decide the end point of a dependency line. { bool found = false; int consLane = 0; float consLaneY = consBaseY; foreach (var segment in consinsn.StageSegments) { if (consLane != 0 && config.DrawInSeparateLane[consLane]) { consLaneY += coordinateSystem.Cell.Height; consy = consLaneY; } else { consy = consBaseY; } List <Insn.Stage> consStages = segment; for (int i = consStages.Count - 1; i >= 0; i--) { Insn.Stage stage = consStages[i]; if (IsExecStageId(consLane, stage.Id)) { consx = coordinateSystem.XAtCycle(consinsn.StartCycle + stage.BeginRelCycle) + coordinateSystem.Grid.Width * 0.2f; found = true; break; } } if (found) { break; } consLane++; } if (!found) { return; } } // Draw a dependency line. if (currentViewSetting.DrawDependencyInsideCurve && DrawDependencyInsideCurve) { float xDiff = (consx - prodx) * 0.6f; float yDiff = 0; { PointF[] pts = new PointF[4]; pts[0] = new PointF(prodx, prody); pts[1] = new PointF(prodx + xDiff, prody + yDiff); pts[2] = new PointF(consx - xDiff, consy - yDiff); pts[3] = new PointF(consx, consy); g.DrawBezier(dependencyArrowPen, pts[0], pts[1], pts[2], pts[3]); } // Draw a dependency arrow head. { PointF arrowVector = new PointF( (consx - prodx) * 3, consy - prody ); float norm = (float)Math.Sqrt(arrowVector.X * arrowVector.X + arrowVector.Y * arrowVector.Y); float f = currentViewSetting.DependencyArrowheadLength / norm; arrowVector.X *= f; arrowVector.Y *= f; DrawArrowhead( g, dependencyArrowBrush, new PointF(consx, consy), arrowVector, 0.8f ); } } if (currentViewSetting.DrawDependencyInsideLine && DrawDependencyInsideLine) { g.DrawLine(dependencyArrowPen, prodx, prody, consx, consy); PointF v = new PointF(consx - prodx, consy - prody); float norm = (float)Math.Sqrt(v.X * v.X + v.Y * v.Y); float f = currentViewSetting.DependencyArrowheadLength / norm; v.X *= f; v.Y *= f; DrawArrowhead(g, dependencyArrowBrush, new PointF(consx, consy), v, 0.8f); } } }
public void ContextMenuAddParent(object sender, RoutedEventArgs e) { if (!(sender is MenuItem)) { return; } string guid = ((MenuItem)sender).Name.Substring(1, ((MenuItem)sender).Name.Length - 1).Replace("_", "-"); DependencyArrow link = null; UMLClassBox fblock = null; UMLClassBox sblock = null; foreach (var val in elements) { if (val is DependencyArrow && (val as DependencyArrow).getFGUID() == guid && ((val as DependencyArrow).GetTip() == DependencyArrow.Tips.ImplementationArrow || (val as DependencyArrow).GetTip() == DependencyArrow.Tips.DerivArrow)) { link = val as DependencyArrow; } else if (val is UMLClassBox && (val as UMLClassBox).getGuid() == guid) { fblock = val as UMLClassBox; } if (link != null && fblock != null) { break; } } if (link != null) { foreach (var umlElement in elements) { if (umlElement is UMLClassBox && (umlElement as UMLClassBox).getGuid() == link.getSGUID()) { sblock = umlElement as UMLClassBox; break; } } } ParentDependencyWindow dependencyWindow = new ParentDependencyWindow(fblock.getFieldsList(), fblock.getMethodsList()); if (dependencyWindow.ShowDialog() != true) { return; } if (link != null) { elements.Remove(link); link.removeGraphicFromCanvas(drawCanvas); } UMLClassBox newbox = dependencyWindow.generateParent(fblock.GetCenterPoint(), classes); fblock.move(new Point(160, 0), drawCanvas); DependencyArrow arrow = new DependencyArrow(fblock, newbox, DependencyArrow.Tips.DerivArrow); arrow.draw(drawCanvas); newbox.draw(drawCanvas); newbox.beforeLoadSets(classes); newbox.initMenu(this); elements.Add(arrow); elements.Add(newbox); if (link != null) { DependencyArrow sArrow = new DependencyArrow(newbox, sblock, link.GetTip()); sArrow.draw(drawCanvas); elements.Add(sArrow); } //TODO: удалять отдельно связи }