Exemplo n.º 1
0
        private void MakeTemporaryLink()
        {
            if (myLink == null)
            {
                // create a new link starting at the bottom port of the first block
                GoLink l = new GoLink();
                l.Orthogonal = true;

                GoPort fp = new GoPort();
                fp.Style    = GoPortStyle.Rectangle;
                fp.FromSpot = this.Predecessor.BottomPort.FromSpot;
                fp.Bounds   = this.Predecessor.BottomPort.Bounds;
                l.FromPort  = fp;

                GoPort tp = new GoPort();
                tp.Size     = new SizeF(1, 1);
                tp.Position = this.LastInput.DocPoint;
                tp.ToSpot   = GoObject.MiddleTop;
                l.ToPort    = tp;

                // the link is temporarily a view object
                this.View.Layers.Default.Add(l);
                myLink = l;
            }
        }
Exemplo n.º 2
0
        private GoLink DrawEdge(GoNodeWrapper nodeWrapper, GoView myView, InstructionNode backNode, GoLayer layer, Pen pen)
        {
            GoLink link            = new GoLink();
            var    backNodeWrapper = GetNodeWrapper(backNode);

            link.Pen    = pen;
            link.ToPort = nodeWrapper.Node.LeftPort;
            if (backNodeWrapper.Node == nodeWrapper.Node)
            {
                link.FromPort = backNodeWrapper.Node.RightPort;
                link.Style    = GoStrokeStyle.Bezier;
                link.CalculateRoute();
                foreach (int index in new[] { 1, 2 })
                {
                    link.SetPoint(index, new PointF(link.GetPoint(index).X, link.GetPoint(index).Y - 40));
                }
            }
            else
            {
                link.FromPort = backNodeWrapper.Node.RightPort;
            }
            layer.Add(link);
            link.PenWidth = 3;
            return(link);
        }
Exemplo n.º 3
0
        /// <summary>
        /// The user can relink if the view allows it and if the handle
        /// found at the input event point has an ID that indicates it
        /// is relinkable.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// This calls <see cref="M:Northwoods.Go.GoToolRelinking.PickRelinkHandle(System.Drawing.PointF)" /> to find a handle.
        /// The <see cref="P:Northwoods.Go.IGoHandle.HandleID" /> should be either
        /// <see cref="F:Northwoods.Go.GoLink.RelinkableFromHandle" /> or
        /// <see cref="F:Northwoods.Go.GoLink.RelinkableToHandle" />.  The ID also
        /// determines which end of the link is disconnected.
        /// This sets <see cref="P:Northwoods.Go.GoToolLinking.Link" /> and <see cref="P:Northwoods.Go.GoToolLinking.Forwards" />
        /// properties for initializing this tool before the call to <see cref="M:Northwoods.Go.GoToolRelinking.Start" />.
        /// </remarks>
        public override bool CanStart()
        {
            if (base.FirstInput.IsContextButton)
            {
                return(false);
            }
            if (!base.View.CanLinkObjects())
            {
                return(false);
            }
            IGoHandle goHandle = PickRelinkHandle(base.FirstInput.DocPoint);

            if (goHandle == null)
            {
                return(false);
            }
            if (goHandle.HandleID == 1024)
            {
                base.CurrentObject = goHandle.HandledObject;
                IGoLink goLink = goHandle.SelectedObject as IGoLink;
                if (goLink is GoLink)
                {
                    GoLink goLink2 = (GoLink)goLink;
                    if (goLink2.AbstractLink != null)
                    {
                        goLink = goLink2.AbstractLink;
                    }
                }
                if (goLink == null)
                {
                    return(false);
                }
                base.Link     = goLink;
                base.Forwards = false;
                return(true);
            }
            if (goHandle.HandleID == 1025)
            {
                base.CurrentObject = goHandle.HandledObject;
                IGoLink goLink3 = goHandle.SelectedObject as IGoLink;
                if (goLink3 is GoLink)
                {
                    GoLink goLink4 = (GoLink)goLink3;
                    if (goLink4.AbstractLink != null)
                    {
                        goLink3 = goLink4.AbstractLink;
                    }
                }
                if (goLink3 == null)
                {
                    return(false);
                }
                base.Link     = goLink3;
                base.Forwards = true;
                return(true);
            }
            return(false);
        }
Exemplo n.º 4
0
        private void DrawingLink(GoBasicNode fromNode, GoBasicNode toNode)
        {
            GoLink link = new GoLink();

            link.ToArrow  = true;
            link.PenColor = Color.Red;
            link.FromPort = fromNode.Port;
            link.ToPort   = toNode.Port;
            goView1.Document.Add(link);
        }
Exemplo n.º 5
0
        internal float GetEndSegmentLength(GoBoxPortLinkInfo info)
        {
            float endSegmentLength = EndSegmentLength;
            int   num = info.IndexOnSide;

            if (num < 0)
            {
                return(endSegmentLength);
            }
            int countOnSide = info.CountOnSide;

            if (countOnSide <= 1)
            {
                return(endSegmentLength);
            }
            IGoLink link = info.Link;

            if (!GoLink.IsOrtho(link))
            {
                return(endSegmentLength);
            }
            IGoPort otherPort = link.GetOtherPort(this);

            if (otherPort == null)
            {
                return(endSegmentLength);
            }
            GoObject goObject = otherPort.GoObject;

            if (goObject == null)
            {
                return(endSegmentLength);
            }
            PointF center  = goObject.Center;
            PointF center2 = base.Center;

            checked
            {
                if (info.Side == 256 || info.Side == 128)
                {
                    num = countOnSide - 1 - num;
                }
                float num2 = 8f;
                bool  flag = info.Side == 256 || info.Side == 64;
                if (flag ? (center.Y < center2.Y) : (center.X < center2.X))
                {
                    return(endSegmentLength + (float)num * num2);
                }
                if (flag ? (center.Y == center2.Y) : (center.X == center2.X))
                {
                    return(endSegmentLength);
                }
                return(endSegmentLength + (float)(countOnSide - 1 - num) * num2);
            }
        }
Exemplo n.º 6
0
        public GoLink MakeRelationship(GoTextNode a, GoTextNode b)
        {
            var l = new GoLink();

            l.Orthogonal = true;
            l.Style      = GoStrokeStyle.RoundedLine;
            l.Brush      = null;
            l.FromPort   = a.BottomPort;
            l.ToPort     = b.TopPort;
            return(l);
        }
Exemplo n.º 7
0
        private void goView_LinkCreated(object sender, Northwoods.Go.GoSelectionEventArgs e)
        {
            GoLink link = e.GoObject as GoLink;

            if (link != null)
            {
                Color c = Color.Black;
                link.PenColor   = c;
                link.PenWidth   = 2;
                link.BrushColor = c;
            }
        }
Exemplo n.º 8
0
        public void AddLink(TextNode fromNode, TextNode toNode)
        {
            GoLink link = new GoLink();

            link.FromPort   = fromNode.RightPort;
            link.ToPort     = toNode.LeftPort;
            link.Selectable = false;
            link.PenColor   = myExtendsPenColor;
            link.PenWidth   = 2;

            myView.Document.LinksLayer.Add(link);
        }
Exemplo n.º 9
0
        // When a link is drawn by the user, give it a random color
        private void goView1_LinkCreated(object sender, Northwoods.Go.GoSelectionEventArgs e)
        {
            initListView("1.2");
            var    res  = goView1.Document;
            GoLink link = e.GoObject as GoLink;

            if (link != null)
            {
                Color c = GetRandomColor(100);
                link.PenColor   = c;
                link.PenWidth   = 2;
                link.BrushColor = c;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Determine the angle the port at the other end makes with this port.
        /// </summary>
        /// <param name="link"></param>
        /// <returns>the angle in degrees</returns>
        public virtual float GetAngle(IGoLink link)
        {
            if (link == null)
            {
                return(0f);
            }
            IGoPort goPort = link.GetOtherPort(this);

            if (goPort == null)
            {
                if (link.FromPort != null && link.FromPort.GoObject != null && link.FromPort.GoObject.Bounds == Bounds)
                {
                    goPort = link.ToPort;
                }
                else if (link.ToPort != null && link.ToPort.GoObject != null && link.ToPort.GoObject.Bounds == Bounds)
                {
                    goPort = link.FromPort;
                }
            }
            if (goPort == null)
            {
                return(0f);
            }
            GoObject goObject = goPort.GoObject;

            if (goObject == null)
            {
                return(0f);
            }
            PointF pointF = goObject.Center;
            PointF center = base.Center;
            GoLink goLink = link as GoLink;

            if (goLink == null)
            {
                GoLabeledLink goLabeledLink = link as GoLabeledLink;
                if (goLabeledLink != null)
                {
                    goLink = goLabeledLink.RealLink;
                }
            }
            if (goLink != null && goLink.PointsCount > 0)
            {
                pointF = ((goLink.FromPort != goPort) ? goLink.GetPoint(checked (goLink.PointsCount - 1)) : goLink.GetPoint(0));
            }
            return(GoStroke.GetAngle(pointF.X - center.X, pointF.Y - center.Y));
        }
Exemplo n.º 11
0
 private void DrawFlowLinks(GoNodeWrapper nodeWrapper, GoView myView)
 {
     foreach (InstructionNode wrapper in nodeWrapper.InstructionNode.ProgramFlowForwardRoutes)
     {
         Color  randomColor;
         GoLink link = new GoLink();
         link.FromArrow = true;
         link.ToPort    = nodeWrapper.Node.RightPort;
         link.Pen       = new Pen(link.Pen.Brush)
         {
             DashStyle = DashStyle.Dash
         };
         link.PenWidth   = 1;
         link.Style      = GoStrokeStyle.RoundedLineWithJumpGaps;
         link.BrushStyle = GoBrushStyle.EllipseGradient;
         var backNode = GetNodeWrapper(wrapper);
         link.FromPort = backNode.Node.LeftPort;
         myView.Document.Add(link);
         randomColor   = Color.Black;
         link.PenColor = randomColor;
     }
 }
Exemplo n.º 12
0
        private void DrawPairingEdge(GoTextNodeHoverable sourceGoNode, GoTextNodeHoverable imageGoNode, double score, GoLayer layer)
        {
            GoLink link = new GoLink();

            double pairingScore = score;

            if (pairingScore < 0)
            {
                pairingScore = 0;
            }
            Color edgeColor = Color.FromArgb(Convert.ToInt32(255 - 255 * pairingScore), Convert.ToInt32(255 * pairingScore), 0);

            link.ToolTipText = (pairingScore.ToString());
            link.Pen         = new Pen(edgeColor);
            if (sourceGoNode == null || imageGoNode == null)
            {
                return;
            }
            link.ToPort   = sourceGoNode.LeftPort;
            link.FromPort = imageGoNode.RightPort;
            layer.Add(link);
            link.PenWidth = 3;
        }
 private void unlinkBaseNodes(IBaseLink baseLink, GoLink goLink)
 {
     Unlink(baseLink.GetFromNode(), baseLink.GetToNode(), goLink.FromPort.UserObject, goLink.ToPort.UserObject);
 }
Exemplo n.º 14
0
 public void DrawLinks(GoView myView)
 {
     dataLinksLayer          = myView.Document.Layers.CreateNewLayerAfter(myView.Document.Layers.Default);
     flowAffectingLinksLayer = myView.Document.Layers.CreateNewLayerAfter(myView.Document.Layers.Default);
     flowRoutesLinksLayer    = myView.Document.Layers.CreateNewLayerAfter(myView.Document.Layers.Default);
     foreach (var nodeWrapper in nodeWrappers)
     {
         foreach (var indexedArg in nodeWrapper.InstructionNode.DataFlowBackRelated)
         {
             try
             {
                 Color  linkColor = GetPredefinedDataLinkColor(indexedArg.ArgIndex);
                 GoLink edge      = DrawEdge(nodeWrapper, myView, indexedArg.Argument, dataLinksLayer, new Pen(linkColor));
                 edge.ToolTipText = indexedArg.ArgIndex.ToString();
             }
             catch
             {
                 Console.WriteLine("Failed to draw edge");
             }
         }
         foreach (var branch in nodeWrapper.InstructionNode.BranchProperties.Branches.Where(x => !(x is BaseBranch)))
         {
             try
             {
                 Color  linkColor = GetPredefinedFlowAffectLinkColor((int)branch.OriginatingNodeIndex);
                 GoLink edge      = DrawEdge(nodeWrapper, myView, branch.OriginatingNode, flowAffectingLinksLayer, new Pen(linkColor));
                 edge.ToolTipText = branch.Index.ToString() + " " + edge.PenColor.R;
             }
             catch
             {
                 Console.WriteLine("Failed to draw edge");
             }
         }
         foreach (var backRouteNode in nodeWrapper.InstructionNode.ProgramFlowBackRoutes)
         {
             try
             {
                 DrawEdge(nodeWrapper, myView, backRouteNode, flowRoutesLinksLayer, new Pen(Color.Black)
                 {
                     DashStyle = DashStyle.Dash
                 });
             }
             catch
             {
                 Console.WriteLine("Failed to draw edge");
             }
         }
         foreach (var backRelatedNode in nodeWrapper.InstructionNode.SingleUnitBackRelated)
         {
             try
             {
                 DrawEdge(nodeWrapper, myView, backRelatedNode, flowRoutesLinksLayer, new Pen(Color.Blue)
                 {
                     DashStyle = DashStyle.Dot
                 });
             }
             catch
             { }
         }
     }
 }
Exemplo n.º 15
0
        private void createDiagram(List <string[]> rawData)
        {
            PointF ref_point = new PointF(100, 100);

            // Nodes Creation
            for (int i = 0; i < indexNumber; i++)
            {
                GoBasicNode node = new GoBasicNode(GoFigure.Circle);
                node.Text     = timeSeq.ElementAt(i).Key.ToString();
                node.Location = new PointF(ref_point.X + (i * 100), ref_point.Y);
                nodes[i]      = node;
            }

            //Links Creation
            for (int i = 0; i < rawData.Count; i++)
            {
                GoLink link = new GoLink();
                link.ToArrow = true;

                // getting associated node
                string[] dt           = rawData.ElementAt(i);
                var      nodesAquired = Array.FindAll(nodes, s => s.Text == dt[0]);
                var      nodeTo       = nodesAquired[0];

                nodesAquired = Array.FindAll(nodes, s => s.Text == dt[1] && s.Text != "0");

                if (nodesAquired.Length > 0)
                {
                    var nodeFrom = nodesAquired[0];

                    link.FromPort = nodeFrom.Port;
                    link.ToPort   = nodeTo.Port;
                    links[i]      = link;
                }
            }

            // Add All Nodes to doc
            foreach (var item in nodes)
            {
                goViewDiagram.Document.Add(item);
            }

            // Add All Links to doc
            foreach (var item in links)
            {
                if (item != null)
                {
                    goViewDiagram.Document.Add(item);
                }
            }

            // Perform layout
            GoLayoutTree layout = new GoLayoutTree();

            layout.Document = goViewDiagram.Document;
            layout.PerformLayout();

            foreach (var item in nodes)
            {
                PointF current = item.Location;
                item.Location = new PointF(current.X + 50, current.Y + 250);
            }
        }
        private void DFA_Painter(object sender, PaintEventArgs e)
        {
            GoView myView = new GoView();

            myView.Dock = DockStyle.Fill;
            this.Controls.Add(myView);
            MFA myMFA = Program.globalMFA;

            //获取MFA的所有状态
            String[] stateSet = getAllStateOfMFA(myMFA);
            int      stateNum = stateSet.Length; //椭圆的个数

            int[] startIDArray = new int[10];    //每一列的开始状态编号
            startIDArray[0] = 0;
            for (int i = 1; i < 10; i++)
            {
                startIDArray[i] = startIDArray[i - 1] + i;
                //MessageBox.Show(startIDArray[i].ToString());
            }
            GoBasicNode[] myNode = new GoBasicNode[stateNum];
            for (int i = 0; i < stateNum; i++)
            {
                //创建节点
                myNode[i]                  = new GoBasicNode();
                myNode[i].Text             = i.ToString();
                myNode[i].Height           = 50;
                myNode[i].Width            = 50;
                myNode[i].Editable         = false;
                myNode[i].Shape.BrushColor = Color.White;
                if (i == 0)
                {
                    myNode[i].Shape.BrushColor = Color.Thistle;
                    myNode[i].Height           = 55;
                    myNode[i].Width            = 55;
                }
                //标记终态
                if (myMFA.MFA_END.Contains(i.ToString()))
                {
                    myNode[i].Shape.BrushColor = Color.Green;
                    myNode[i].Height           = 55;
                    myNode[i].Width            = 55;
                }
                //设置节点位置
                int   row    = getPositionOfState(startIDArray, i)[0];
                int   column = getPositionOfState(startIDArray, i)[1];
                float X      = 0;
                float Y      = 0;
                if (row % 2 != 0)
                {
                    X = column * intervalHorizonal + row * 20;
                }
                else
                {
                    X = column * intervalHorizonal - row * 20;
                }
                if (column % 2 == 0)
                {
                    Y = row * intervalVertical + column * 20;
                }
                else
                {
                    Y = row * intervalVertical - column * 20;
                }
                myNode[i].Position = new PointF(X, Y);
                //向GO视图中添加node控件
                myView.Document.Add(myNode[i]);
            }
            //遍历MFA转换函数,向对应两个状态之间添加连线
            foreach (transformFunction TF in myMFA.MFA_Transform)
            {
                //MessageBox.Show(TF.tranformInfo());
                int    from = int.Parse(TF.from);
                String by   = TF.by;
                int    to   = int.Parse(TF.to);
                if (from == 34)
                {
                    #region
                    GoBasicNode node = new GoBasicNode();
                    node.Size             = new SizeF(0, 0);
                    node.Text             = by;
                    node.Shape.BrushColor = Color.White;
                    //设置中间节点位置在from和to节点中间
                    node.Position = new PointF((myNode[from].Position.X + myNode[to].Position.X) / 2,
                                               (myNode[from].Position.Y + myNode[to].Position.Y) / 2);
                    myView.Document.Add(node);
                    #endregion
                    GoLink link1 = new GoLink();
                    link1.ToArrow  = false;
                    link1.FromPort = myNode[from].Port;
                    link1.ToPort   = node.Port;
                    link1.Style    = GoStrokeStyle.RoundedLineWithJumpOvers;
                    myView.Document.Add(link1);
                    GoLink link2 = new GoLink();
                    link2.ToArrow  = true;
                    link1.Style    = GoStrokeStyle.Bezier;
                    link2.FromPort = node.Port;
                    link2.ToPort   = myNode[to].Port;
                    link2.Style    = GoStrokeStyle.RoundedLineWithJumpOvers;
                    myView.Document.Add(link2);
                }
                else
                {
                    GoLabeledLink link = new GoLabeledLink();
                    link.ToArrow  = true;
                    link.FromPort = myNode[from].Port;
                    link.ToPort   = myNode[to].Port;
                    GoText text = new GoText();
                    text.Text     = by;
                    link.MidLabel = text;
                    myView.Document.Add(link);
                }
            }
            GoText        MFAInfoText = new GoText();
            StringBuilder SB          = new StringBuilder();
            SB.Append("项目编号        项目族信息\r\n");
            for (int i = 0; i < myMFA.stateSet.Length; i++)
            {
                SB.Append(i.ToString());
                SB.Append("                ");
                foreach (String item in myMFA.stateSet[i].state)
                {
                    SB.Append(item);
                    SB.Append(";");
                }
                SB.Append("\r\n");
            }
            SB.Append("\r\n");
            SB.Append("DFA转换函数");
            SB.Append("\r\n");
            foreach (transformFunction TF in myMFA.MFA_Transform)
            {
                SB.Append(TF.tranformInfo());
                SB.Append("\r\n");
            }
            MFAInfoText.Text         = SB.ToString();
            MFAInfoText.Multiline    = true;
            MFAInfoText.Bold         = true;
            MFAInfoText.AutoRescales = true;
            MFAInfoText.Position     = new PointF(10, 50);
            myView.Document.Add(MFAInfoText);
        }
Exemplo n.º 17
0
 /// <summary>
 /// This convenience method decides if the given link is supposed to
 /// be drawn with all of its segments orthogonal.
 /// </summary>
 /// <param name="link"></param>
 /// <returns>true if the link is believed to be drawn with orthogonal segments</returns>
 public virtual bool IsOrthogonal(IGoLink link)
 {
     return(GoLink.IsOrtho(link));
 }