Exemplo n.º 1
0
        // отрисовка диаграммы
        private void DrawDiagram()
        {
            FrameDiagram.ClearAll();
            List<Frame> curList = ClassFactory.kBase.FrameList();
            foreach (Frame frm in curList)
            {
                // рисование вершин
                ShapeNode node = new ShapeNode { Text = frm.FrameName, Id = frm.FrameId, Brush = new SolidBrush(Color.PowderBlue), Shape = Shapes.Ellipse };
                node.Font = new System.Drawing.Font("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                node.TextFormat.Alignment = StringAlignment.Center;
                node.TextFormat.LineAlignment = StringAlignment.Center;
                node.SetBounds(new RectangleF(new PointF(frm.X, frm.Y), new SizeF(100, 30)), true, true);
                FrameDiagram.Nodes.Add(node);

                //if (frm.IsA != null)
                //{
                //    DiagramNode from, destination;
                //    from=
                //    DiagramLink link=new DiagramLink(FrameDiagram, origin, destination);

                //    //FrameDiagram.Links.Add(
                //}

            }

            foreach (Frame frm in curList)
            {
                foreach (Slot slot in frm.FrameSlots)
                    if (slot.SlotType == Classes.SlotType.Frame)
                    {
                        //значит, это субфрейм. Надо нарисовать дугу :)
                        ShapeNode nodeSubframe = findNodeById(slot.frameId);
                        ShapeNode nodeMainFrame = findNodeById(frm.FrameId);
                        DiagramLink link = new DiagramLink(FrameDiagram, nodeSubframe, nodeMainFrame);
                        link.Text = "Sub";
                        link.TextColor = Color.DarkBlue;
                        link.Pen.Color = Color.Blue;
                        FrameDiagram.Links.Add(link);
                    }
            }

            //link.HeadShape = FrameDiagram.Nodes[1];
            foreach (ShapeNode node in FrameDiagram.Nodes)
            {
                Frame from = ClassFactory.kBase.FrameList().Find(f => f.FrameId == (int)node.Id);
                if (from.IsA != null)
                {
                    if (from.IsA.frameId != -1)
                    {
                        ShapeNode nodeTo = null;
                        int idTo = from.IsA.frameId;

                        foreach (ShapeNode innerNode in FrameDiagram.Nodes)
                            if (((int)innerNode.Id) == idTo)
                            {
                                nodeTo = innerNode;
                                break;
                            }
                        DiagramLink link = new DiagramLink(FrameDiagram, node, nodeTo);
                        link.Text = "Is_a";
                        link.TextColor = Color.DarkRed;
                        link.Pen.Color = Color.Red;
                        FrameDiagram.Links.Add(link);
                    }
                }
                //if (node.GetBounds().Contains(e.X, e.Y))
                //{
                //    ClassFactory.kBase.FrameList().Find(f => f.FrameId == (int)node.Id).X = e.X;
                //    ClassFactory.kBase.FrameList().Find(f => f.FrameId == (int)node.Id).Y = e.Y;
                //}
            }
            //FrameDiagram.Links.
        }
Exemplo n.º 2
0
 // закидываем создаем новый фрейм и отображаем
 private void добавитьФреймшаблонToolStripMenuItem_Click(object sender, EventArgs e)
 {
     AddFrameFrm frm = new AddFrameFrm();
     if (frm.ShowDialog()== DialogResult.OK)
     {
         Random rand = new Random();
         Frame frame = new Frame { FrameId = ClassFactory.kBase.GetMaxNodeId(1), FrameName = frm.TextBox };
         //frame.FrameSlots.Add(new Slot { SlotName = "slot" + ClassFactory.kBase.GetMaxSlotId(1), SlotId = 0, SlotInheritance = SlotInherit.Override, SlotType = Classes.SlotType.Integer });
         //frame.FrameSlots.Add(new Slot { SlotName = "slo1t" + ClassFactory.kBase.GetMaxSlotId(1), SlotId = 1, SlotInheritance = SlotInherit.Same, SlotType = Classes.SlotType.Frame });
         ShapeNode node = new ShapeNode { Text = frame.FrameName, Id = frame.FrameId, Brush = new SolidBrush(Color.PowderBlue), Shape = Shapes.Ellipse };
         node.SetBounds(new RectangleF(new PointF(rand.Next(100, 400), rand.Next(100, 400)), new SizeF(100, 30)), true, true);
         node.Font = new System.Drawing.Font("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
         node.TextFormat.Alignment = StringAlignment.Center;
         node.TextFormat.LineAlignment = StringAlignment.Center;
         ClassFactory.isSaved = false;
         frame.X = node.GetBounds().X;
         frame.Y = node.GetBounds().Y;
         FrameDiagram.Nodes.Add(node);
         ClassFactory.kBase.AddFrame(frame);
         TreeNode frameitem = new TreeNode { Text = frame.FrameName };
         FrameTreeView.Nodes.Add(frameitem);
     }
 }