コード例 #1
0
        private void ConnectToNearbyNode(DiagramLink link)
        {
            // connect to a nearby origin node
            var origin = diagram.Nodes.OrderBy(n =>
                                               MindFusion.Utilities.Distance(n.GetCenter(), link.StartPoint)).FirstOrDefault();

            if (origin != null)
            {
                var distance = MindFusion.Utilities.Distance(origin.GetCenter(), link.StartPoint);
                if (distance < 120)
                {
                    link.Origin = origin;
                    link.Route();
                }
            }

            // connect to a nearby destination node
            var destination = diagram.Nodes.Where(n => n != origin).OrderBy(n =>
                                                                            MindFusion.Utilities.Distance(n.GetCenter(), link.EndPoint)).FirstOrDefault();

            if (destination != null)
            {
                var distance = MindFusion.Utilities.Distance(destination.GetCenter(), link.EndPoint);
                if (distance < 120)
                {
                    link.Destination = destination;
                    link.Route();
                }
            }
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: IvannaBaglay/OS
        public ShapeNode RBuildTree(Diagram parent)
        {
            ShapeNode node = new ShapeNode(parent)
            {
                Bounds = new Rect(new Point(), MainWindow.NodeSize),
                Text   = Key.ToString(),
                Tag    = this
            };

            parent.Nodes.Add(node);

            if (LeftChild != null)
            {
                var childNode = LeftChild.RBuildTree(parent);
                childNode.AttachTo(node, AttachToNode.TopLeft);


                var link = new DiagramLink(parent, node, childNode);
                parent.Links.Add(link);
            }

            if (RightChild != null)
            {
                var childNode = RightChild.RBuildTree(parent);
                childNode.AttachTo(node, AttachToNode.TopRight);

                var link = new DiagramLink(parent, node, childNode);
                parent.Links.Add(link);
            }

            return(node);
        }
コード例 #3
0
        private void CreateLink(TreeViewNode outgoing, TreeViewNode incoming)
        {
            DiagramLink tmp = diagram1.Factory.CreateDiagramLink(outgoing, incoming);

            tmp.AddLabel((string)incoming.Id);
            tmp.Id = (string)outgoing.Id + (string)incoming.Id;
            //incoming.AttachTo(outgoing, AttachToNode.BottomCenter);
            tmp.AutoRoute = true;
        }
コード例 #4
0
 private void diagram1_LinkClicked(object sender, LinkEventArgs e)
 {
     if (e.MouseButton == MouseButton.Right)
     {
         Point point = diagramView1.DocToClient((e.MousePosition));
         point.X = point.X + diagramView1.Bounds.X;
         contextMenuStrip1.Show(this, point);
         link = e.Link;
     }
 }
コード例 #5
0
        private ShapeNode generateShapeNode(IVisualizableNode visNode, ShapeNode parent)
        {
            var node = generateShapeNode(visNode);

            node.AttachTo(parent, AttachToNode.BottomCenter);
            var link = new DiagramLink(treeDiagram, parent, node);

            styleLink(link);
            treeDiagram.Links.Add(link);
            return(node);
        }
コード例 #6
0
        DiagramLink _rightLink; //связь по которой щелкнули правой кнопкой
        private void DdLinkClicked(object sender, LinkEventArgs e)
        {
            myContextMenu.IsEnabled  = false;
            myContextMenu.Visibility = Visibility.Collapsed;

            if (e.MouseButton == MouseButton.Right && CanEdit)
            {
                _rightLink = e.Link;
                myContextMenu.IsEnabled   = true;
                myContextMenu.Visibility  = Visibility.Visible;
                myContextMenu.DataContext = MenuOptionsLink;
            }
        }
コード例 #7
0
        private void CreateLink(TreeViewNode outgoingNode, TreeViewItem outgoingItem, TreeViewNode incoming)
        {
            //DiagramLink tmp = diagram1.Factory.CreateDiagramLink(outgoingNode, incoming);
            DiagramLink tmp = new DiagramLink(diagram1);

            tmp.OriginConnection = new TreeViewConnectionPoint(outgoingNode, tmp, false, outgoingItem);
            outgoingItem.OutgoingLinks.Add(tmp);
            tmp.DestinationConnection = new ConnectionPoint(incoming, tmp, true);
            incoming.IncomingLinks.Add(tmp);
            tmp.AddLabel((string)incoming.Id);
            tmp.Id        = outgoingItem.Label.Substring(11) + (string)incoming.Id;
            tmp.AutoRoute = true;
            diagram1.Links.Add(tmp);
        }
コード例 #8
0
        public virtual void UpdateDiscreteAngleForces(DiagramLink diagramLink, double linkMomentConstant)
        {
            if (diagramLink.PreferredAngles == null || diagramLink.PreferredAngles.Length == 0)
            {
                return;
            }

            var startNode = diagramLink.StartNode;
            var endNode   = diagramLink.EndNode;

            var vectorToConnectedNode   = endNode.Pos - startNode.Pos;
            var vectorToConnectedNode3D = new Vector3D(vectorToConnectedNode.X, vectorToConnectedNode.Y, 0);

            vectorToConnectedNode.Normalize();
            var    rotateClockwiseVector3D        = Vector3D.CrossProduct(vectorToConnectedNode3D, new Vector3D(0, 0, 1));
            var    rotateCounterClockwiseVector3D = Vector3D.CrossProduct(vectorToConnectedNode3D, new Vector3D(0, 0, -1));
            var    rotateClockwiseVector          = new Vector(rotateClockwiseVector3D.X, rotateClockwiseVector3D.Y);
            var    rotateCounterClockwiseVector   = new Vector(rotateCounterClockwiseVector3D.X, rotateCounterClockwiseVector3D.Y);
            double angle0 = diagramLink.Angle0;

            // Try to refactor enum into array of doubles
            double[] preferredAngles = diagramLink.PreferredAngles;
            double   angle;
            double   currentPreferredAngle = GetPreferredAngle(angle0, preferredAngles, out angle);
            bool     rotateClockwise       = angle0 - currentPreferredAngle > 0;

            // Let's say the preferred angles are 45, 135, 225 and 315
            // Then the link forces should be continuous around these angles.
            // This is currently not the case when we choose preferred angle and disrespect the rest of the angles.
            // Then we get a labiel evenwicht: one small movement to the left or right of angle 0, and the
            // link will be drawn towards 45 or -45 degrees.
            // To prevent discontinuities, we cannot choose a preferred angle: all the angles should always exert a force.
            // This only works if we define the angles between the preferred angles (in this example, 0, 90, 180, 270),
            // if those angles define the moment forces on the link and if the forces increase if the angle gets bigger.
            //

            var vector = rotateClockwise ? rotateClockwiseVector : rotateCounterClockwiseVector;

            var torsionForce = angle * linkMomentConstant;
            var force        = torsionForce * diagramLink.HalfLength; // Force is exerted from the middle of the link

            startNode.AddForce(ForceType.DiscreteAngles, vector * force);
            endNode.AddForce(ForceType.DiscreteAngles, -vector * force);
        }
コード例 #9
0
        private void _connectorList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }

            // Draw the item
            ListBox_DrawItem(_connectorList, e);

            Pen   pen = new Pen(Color.Black);
            Point p0  = new Point(e.Bounds.X + 2, e.Bounds.Y + 13);
            Point p1  = new Point(e.Bounds.X + 19, e.Bounds.Y + 13);

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.DrawLine(Pens.Black, p0, p1);

            DiagramLink.DrawArrowhead(new GdiGraphics(e.Graphics), pen, Brushes.LightSkyBlue,
                                      _connectors[e.Index].Head, new PointF(50, 0), p1, p0, 12F, false);

            pen.Dispose();
        }
コード例 #10
0
        /// <summary>
        /// Calculates the attraction force between two connected nodes, using the specified spring length.
        /// </summary>
        private static Vector CalcAttractionForce(DiagramLink diagramLink, double springLength, double attractionConstant)
        {
            if (diagramLink.StartNode == diagramLink.EndNode)
            {
                return(new Vector(0, 0));
            }
            var proximity = Math.Max(diagramLink.StartNode.GetDistanceToNode(diagramLink.EndNode), 0);
            //var proximity = CalcDistance(a, b);

            // Hooke's Law: F = -kx
            var force = attractionConstant * (proximity - springLength);
            //var force = ATTRACTION_CONSTANT * (proximity - springLength);
            //var angle = GetBearingAngle(a, b);
            //var angle = Math.Atan((b.Y - a.Y) / (b.X - a.X));

            //return new Vector(force * Math.Cos(angle), force * Math.Sin(angle));
            var vector = diagramLink.EndNode.Pos - diagramLink.StartNode.Pos;

            if (vector.Length > 0)
            {
                vector.Normalize();
            }
            return(vector * force);
        }
コード例 #11
0
 private void styleLink(DiagramLink link)
 {
     link.Brush         = new MindFusion.Drawing.SolidBrush(Color.Blue);
     link.HeadShape     = ArrowHeads.Triangle;
     link.HeadShapeSize = 2.5f;
 }
コード例 #12
0
ファイル: MainWindow.xaml.cs プロジェクト: neismit/emds
        void nodeSelected_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ShapeNode node = sender as ShapeNode;
            if (_selectedLink != null)
            {
                DiagramHelper.UnSelectLink(_selectedLink);
                _selectedLink = null;
            }

            if(node == _selectedNode)
            {
                DiagramHelper.UnSelectNode(_selectedNode);
                _selectedNode = null;
                return;
            }

            if (_selectedNode != null)
                DiagramHelper.UnSelectNode(_selectedNode);
            _selectedNode = node;
            DiagramHelper.SelectNode(node);
        }
コード例 #13
0
        private void drawLinks(ShapeNode origin, Circle data)
        {
            ShapeNode letterDestiny = null;

            switch (data.Letter)
            {
            case "q0": letterDestiny = q0;  break;

            case "q1": letterDestiny = q1; break;

            case "q2": letterDestiny = q2; break;

            case "q3": letterDestiny = q3; break;

            case "q4": letterDestiny = q4; break;

            case "A": break;
            }
            if (letterDestiny != null)
            {
                DiagramLink link = new DiagramLink(diagram, origin, letterDestiny);
                link.Text = "Letra";
                diagram.Links.Add(link);
            }

            ShapeNode numberDestiny = null;

            switch (data.Number)
            {
            case "q0": numberDestiny = q0; break;

            case "q1": numberDestiny = q1; break;

            case "q2": numberDestiny = q2; break;

            case "q3": numberDestiny = q3; break;

            case "q4": numberDestiny = q4; break;

            case "A": break;
            }
            if (numberDestiny != null)
            {
                DiagramLink link = new DiagramLink(diagram, origin, numberDestiny);
                link.Text = "Numero";
                diagram.Links.Add(link);
            }

            ShapeNode plusDestiny = null;

            switch (data.PlusSymbol)
            {
            case "q0": plusDestiny = q0; break;

            case "q1": plusDestiny = q1; break;

            case "q2": plusDestiny = q2; break;

            case "q3": plusDestiny = q3; break;

            case "q4": plusDestiny = q4; break;

            case "A": break;
            }
            if (plusDestiny != null)
            {
                DiagramLink link = new DiagramLink(diagram, origin, plusDestiny);
                link.Text = "+";
                diagram.Links.Add(link);
            }

            ShapeNode equalDestiny = null;

            switch (data.EqualSymbol)
            {
            case "q0": equalDestiny = q0; break;

            case "q1": equalDestiny = q1; break;

            case "q2": equalDestiny = q2; break;

            case "q3": equalDestiny = q3; break;

            case "q4": equalDestiny = q4; break;

            case "A": break;
            }
            if (equalDestiny != null)
            {
                DiagramLink link = new DiagramLink(diagram, origin, equalDestiny);
                link.Text = "=";
                diagram.Links.Add(link);
            }
        }
コード例 #14
0
        //根据xml绘制CFG
        public void DrawGraph(object xmlPaths, bool isLog)
        {
            //使用之前,先全部清理掉
            string xmlPath = xmlPaths as string;
            string retu_id = "";
            string Nodenum = "";//结点的个数

            diagram.ClearAll();
            diagram.LinkHeadShape = ArrowHeads.PointerArrow;//设置连线箭头的类型
            GlassEffect effect = new GlassEffect();

            effect.Type      = GlassEffectType.Type4;//设置结点的玻璃效果
            effect.GlowColor = Colors.Black;
            diagram.NodeEffects.Add(effect);

            var nodeMap = new Dictionary <string, DiagramNode>();
            var bounds  = new Rect(30, 30, 10, 2);

            // load the graph xml
            var xml   = XDocument.Load(xmlPath);
            var graph = xml.Element("Graph");

            // load node data
            var sours = graph.Descendants("Source");

            foreach (var sour in sours)//获取exit的结点
            {
                retu_id = sour.Attribute("retNo").Value;
                Nodenum = sour.Attribute("noNum").Value;
            }


            var nodes = graph.Descendants("Node");

            foreach (var node in nodes)
            {
                var diagramNode = diagram.Factory.CreateShapeNode(bounds);

                nodeMap[node.Attribute("id").Value] = diagramNode;
                diagramNode.Text = node.Attribute("name").Value;
                //--调整结点大小以显示全部内容,必须放在设置了内容值之后
                diagramNode.ResizeToFitText(FitSize.KeepRatio);
                diagramNode.TextAlignment = TextAlignment.Left;
            }

            //设置特殊结点的颜色
            ShapeNode s2 = (ShapeNode)nodeMap["0"];//起点位置是绿色

            s2.Brush = Brushes.LightGreen;
            if (Nodenum != "1")                         //对于只有一个结点的情况处理
            {
                s2       = (ShapeNode)nodeMap[retu_id]; //终止位置是红色
                s2.Brush = Brushes.Red;

                // load link data
                Style linkStyle = new Style();
                linkStyle.Setters.Add(new Setter(DiagramLink.BrushProperty, Brushes.Red));//log信息的颜色标记

                var links = graph.Descendants("Link");
                foreach (var link in links)
                {
                    DiagramLink dl = diagram.Factory.CreateDiagramLink(
                        nodeMap[link.Attribute("origin").Value],
                        nodeMap[link.Attribute("target").Value]);

                    if (link.Attribute("label").Value.Equals("True"))//为ifelse 标记形状
                    {
                        ShapeNode s = (ShapeNode)nodeMap[link.Attribute("origin").Value];
                        s.Shape = Shapes.Decision;
                        //s.Brush = Brushes.RoyalBlue;
                        s.TextAlignment = TextAlignment.Center;
                    }

                    //----------log采集的信息显示
                    if (isLog && !link.Attribute("log").Value.Equals("0"))
                    {
                        dl.Style = linkStyle;
                        string logShow = link.Attribute("log").Value.Remove(0, 1);
                        dl.AddLabel(link.Attribute("label").Value + "--" + logShow); //显示运行的步骤信息
                        dl.IntermediateShape = ArrowHeads.PointerArrow;
                    }
                    else
                    {
                        dl.AddLabel(link.Attribute("label").Value);  //添加链接信息
                    }
                    //diagram.DiagramLinkStyle = linkStyle;
                    //Brush a = new Brush();
                    //a.
                    //dl.HeadPen.Brush = Brush;
                }
            }


            // arrange the graph
            var layout = new MindFusion.Diagramming.Wpf.Layout.DecisionLayout();

            //layout.IgnoreNodeSize = false;//使得结点不会覆盖显示
            layout.StartNode = nodeMap["0"];
            layout.Arrange(diagram);//自动布局结点
        }
コード例 #15
0
ファイル: MainWindow.xaml.cs プロジェクト: neismit/emds
        void linkSelect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_selectedNode != null)
            {
                DiagramHelper.UnSelectNode(_selectedNode);
                _selectedNode = null;
            }

            DiagramLink link = sender as DiagramLink;
            if (link == _selectedLink)
            {
                DiagramHelper.UnSelectLink(link);
                _selectedLink = null;
                return;
            }

            if (_selectedLink != null)
                DiagramHelper.UnSelectLink(_selectedLink);
            _selectedLink = sender as DiagramLink;
            DiagramHelper.SelectLink(_selectedLink);
        }
コード例 #16
0
ファイル: DiagramHelper.cs プロジェクト: neismit/emds
 private static void SelectLinkLook(DiagramLink link)
 {
     link.Brush = Brushes.Red;
     link.Stroke = Brushes.Blue;
     link.TextBrush = Brushes.Blue;
     link.FontSize = 16;
     link.FontWeight = FontWeights.Bold;
     link.TextStyle = LinkTextStyle.OverLongestSegment;
     link.ZIndex = 10;
 }
コード例 #17
0
ファイル: DiagramHelper.cs プロジェクト: neismit/emds
 public static void UnSelectLink(DiagramLink link)
 {
     UnSelectNodeLook((ShapeNode)link.Destination);
     UnSelectLinkLook(link);
     UnSelectNodeLook((ShapeNode)link.Origin);
 }
コード例 #18
0
ファイル: DiagramHelper.cs プロジェクト: neismit/emds
 private static void UnSelectLinkLook(DiagramLink link)
 {
     link.Brush = Brushes.Green;
     link.Stroke = Brushes.Black;
     link.TextBrush = Brushes.Black;
     link.FontSize = 14;
     link.FontWeight = FontWeights.Normal;
     link.TextStyle = LinkTextStyle.Center;
     link.ZIndex = 0;
 }
コード例 #19
0
ファイル: Diagram.cs プロジェクト: ironyirina/Semantic-Bar
 public void RaiseLinkTextEdited(DiagramLink link, string oldText, string newText);
コード例 #20
0
ファイル: Form1.cs プロジェクト: ilya-torlin/SavannaFrame
        // отрисовка диаграммы
        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.
        }
コード例 #21
0
ファイル: Diagram.cs プロジェクト: ironyirina/Semantic-Bar
 public bool RaiseLinkTextEditing(DiagramLink link);