Inheritance: EntitiesBase
Beispiel #1
0
    public void Set(DXFStructure dxf, P2D P1, P2D P2, GoLayer goLayer, float ScaleX = 1, float ScaleY = 1)
    {
        lr.material = goLayer.LayerMaterial;
        ZoomAdjust  = goLayer.ZoomAdjust;

        lr.SetVertexCount(2);

        var p1 = new Vector3((float)P1.X * ScaleX, (float)P1.Y * ScaleY, 0);
        var p2 = new Vector3((float)P2.X * ScaleX, (float)P2.Y * ScaleY, 0);

        lr.SetPosition(0, p1);
        lr.SetPosition(1, p2);

        LineLenght = Vector2.Distance(p1, p2) * 2;

        this.gameObject.isStatic = true;

        if (GoView.Content.MaxX < p1.x)
        {
            GoView.Content.MaxX = p1.x;
        }
        if (GoView.Content.MinX > p1.x)
        {
            GoView.Content.MinX = p1.x;
        }

        if (GoView.Content.MaxY < p1.y)
        {
            GoView.Content.MaxY = p1.y;
        }
        if (GoView.Content.MinY > p1.y)
        {
            GoView.Content.MinY = p1.y;
        }
    }
Beispiel #2
0
        public void DrawCloser(GoTextNode originalNode, GoTextNode currentNode, GoLayer layer, float modifier, List <GoTextNode> visited = null)
        {
            if (visited == null)
            {
                visited = new List <GoTextNode>()
                {
                    currentNode
                };
            }

            foreach (GoTextNode backNode in currentNode.LeftPort.Links.Cast <GoLink>().Where(x => x.Layer == layer).Select(x => x.FromNode))
            {
                if (visited.Contains(backNode))
                {
                    continue;
                }
                visited.Add(backNode);
                float xLoc = backNode.Location.X;
                float yLoc = (originalNode.Location.Y + backNode.Location.Y) / modifier;
                backNode.Location = new PointF(xLoc, yLoc);
                if (modifier <= 1)
                {
                    modifier -= 0.1f;
                }
                DrawCloser(originalNode, backNode, layer, modifier, visited);
            }
        }
Beispiel #3
0
 /// <summary>
 /// When a GoControl is added to a document, we need to add corresponding
 /// Controls to all of its views; when it is removed from a document, we
 /// need to remove all of its Controls in all of its views.
 /// </summary>
 /// <param name="oldlayer"></param>
 /// <param name="newlayer"></param>
 /// <param name="mainObj"></param>
 protected override void OnLayerChanged(GoLayer oldlayer, GoLayer newlayer, GoObject mainObj)
 {
     base.OnLayerChanged(oldlayer, newlayer, mainObj);
     if (oldlayer != null && newlayer == null && oldlayer.IsInDocument)
     {
         foreach (KeyValuePair <GoView, Control> item in Map)
         {
             GoView  key   = item.Key;
             Control value = item.Value;
             if (key != null && value != null)
             {
                 DisposeControl(value, key);
             }
         }
         Map.Clear();
     }
     else
     {
         if (oldlayer == null || newlayer != null || !oldlayer.IsInView)
         {
             return;
         }
         GoView  view    = oldlayer.View;
         Control control = FindControl(view);
         if (control != null)
         {
             Map.Remove(view);
             if (control != null)
             {
                 DisposeControl(control, view);
             }
         }
     }
 }
Beispiel #4
0
        public void Initialize(IContainerNode firstNeighborNode, IContainerNode secondNeighborNode)
        {
            GoLayer defaultLayer = Document.DefaultLayer;

            GoSubGraphBase.ReparentToCommonSubGraph(this, (GoObject)firstNeighborNode, (GoObject)secondNeighborNode, true, defaultLayer);

            FirstNeighbor  = firstNeighborNode;
            SecondNeighbor = secondNeighborNode;
            if (FirstNeighbor == null || SecondNeighbor == null)
            {
                throw new OSPSuiteException();
            }

            //Refresh Ports names and postions after connecting both neighbors, if MultiPortContainerNodes are uses
            var multiPortFirstNeighbor  = FirstNeighbor as MultiPortContainerNode;
            var multiPortSecondNeighbor = SecondNeighbor as MultiPortContainerNode;

            if (multiPortFirstNeighbor != null)
            {
                multiPortFirstNeighbor.RefreshPort(_neighbor1Link);
            }
            if (multiPortSecondNeighbor != null)
            {
                multiPortSecondNeighbor.RefreshPort(_neighbor2Link);
            }

            AdjustPosition();
        }
Beispiel #5
0
    // //Update is called once per frame
    //void Update()
    //{
    //    if (GoView.Content.Zoom > LineLenght)
    //    {
    //        lr.enabled = false;
    //        return;
    //    }
    //    lr.enabled = true;
    //    //lr.SetWidth(GoView.Content.Zoom * ZoomAdjust, GoView.Content.Zoom * ZoomAdjust);
    //}
    //设置线段
    public void Set(DXFStructure dxf, LINE item, float ScaleX = 1, float ScaleY = 1)
    {
        var goLayer = GoView.Content.GetLayer(item.C8);
        if (goLayer != null)
        {
            lr.material = goLayer.LayerMaterial;
            ZoomAdjust = goLayer.ZoomAdjust;
        }

        gg = goLayer;

        lr.SetVertexCount(2);

        var p1 = new Vector3((float)item.C10 * ScaleX, (float)item.C20 * ScaleY, (float)item.C30);
        var p2 = new Vector3((float)item.C11 * ScaleX, (float)item.C21 * ScaleY, (float)item.C31);

        lr.SetPosition(0, p1);
        lr.SetPosition(1, p2);

        LineLenght = Vector2.Distance(p1, p2) * 2;

        this.gameObject.isStatic = true;

        if (GoView.Content.MaxX < p1.x)
            GoView.Content.MaxX = p1.x;
        if (GoView.Content.MinX > p1.x)
            GoView.Content.MinX = p1.x;

        if (GoView.Content.MaxY < p1.y)
            GoView.Content.MaxY = p1.y;
        if (GoView.Content.MinY > p1.y)
            GoView.Content.MinY = p1.y;
    }
Beispiel #6
0
    public void Set(DXFStructure dxf, P2D P1, P2D P2, GoLayer goLayer, float ScaleX = 1, float ScaleY = 1)
    {
        lr.material = goLayer.LayerMaterial;
        ZoomAdjust = goLayer.ZoomAdjust;

        lr.SetVertexCount(2);

        var p1 = new Vector3((float)P1.X * ScaleX, (float)P1.Y * ScaleY, 0);
        var p2 = new Vector3((float)P2.X * ScaleX, (float)P2.Y * ScaleY, 0);

        lr.SetPosition(0, p1);
        lr.SetPosition(1, p2);

        LineLenght = Vector2.Distance(p1, p2) * 2;

        this.gameObject.isStatic = true;

        if (GoView.Content.MaxX < p1.x)
            GoView.Content.MaxX = p1.x;
        if (GoView.Content.MinX > p1.x)
            GoView.Content.MinX = p1.x;

        if (GoView.Content.MaxY < p1.y)
            GoView.Content.MaxY = p1.y;
        if (GoView.Content.MinY > p1.y)
            GoView.Content.MinY = p1.y;
    }
Beispiel #7
0
 /// <summary>
 /// If this balloon is removed from the document,
 /// set the <see cref="P:Northwoods.Go.GoBalloon.Anchor" /> property to null.
 /// </summary>
 /// <param name="oldlayer"></param>
 /// <param name="newlayer"></param>
 /// <param name="mainObj"></param>
 protected override void OnLayerChanged(GoLayer oldlayer, GoLayer newlayer, GoObject mainObj)
 {
     base.OnLayerChanged(oldlayer, newlayer, mainObj);
     if (oldlayer != null && newlayer == null && !NoClearAnchors)
     {
         Anchor = null;
     }
 }
Beispiel #8
0
    // //Update is called once per frame
    //void Update()
    //{
    //    if (GoView.Content.Zoom > LineLenght)
    //    {
    //        lr.enabled = false;
    //        return;
    //    }
    //    lr.enabled = true;
    //    //lr.SetWidth(GoView.Content.Zoom * ZoomAdjust, GoView.Content.Zoom * ZoomAdjust);
    //}


    //设置线段
    public void Set(DXFStructure dxf, LINE item, float ScaleX = 1, float ScaleY = 1)
    {
        var goLayer = GoView.Content.GetLayer(item.C8);

        if (goLayer != null)
        {
            lr.material = goLayer.LayerMaterial;
            ZoomAdjust  = goLayer.ZoomAdjust;
        }

        gg = goLayer;

        lr.SetVertexCount(2);

        var p1 = new Vector3((float)item.C10 * ScaleX, (float)item.C20 * ScaleY, (float)item.C30);
        var p2 = new Vector3((float)item.C11 * ScaleX, (float)item.C21 * ScaleY, (float)item.C31);

        lr.SetPosition(0, p1);
        lr.SetPosition(1, p2);

        LineLenght = Vector2.Distance(p1, p2) * 2;

        this.gameObject.isStatic = true;

        if (GoView.Content.MaxX < p1.x)
        {
            GoView.Content.MaxX = p1.x;
        }
        if (GoView.Content.MinX > p1.x)
        {
            GoView.Content.MinX = p1.x;
        }

        if (GoView.Content.MaxY < p1.y)
        {
            GoView.Content.MaxY = p1.y;
        }
        if (GoView.Content.MinY > p1.y)
        {
            GoView.Content.MinY = p1.y;
        }
    }
Beispiel #9
0
        private void SetShape(GoLayer frontLayer, GoLabeledVertexWrapper imageNode)
        {
            var shape = ((GoShape)imageNode.Node.Background);

            shape.BrushColor = colorCode.GetColor(imageNode.LabledVertex.Opcode);
            shape.PenWidth   = 3;
            shape.PenColor   = ImageGraphNodes.Contains(imageNode) ? Color.Green : Color.Orange;
            if (shape.BrushColor.GetBrightness() < 0.4)
            {
                imageNode.Node.Label.TextColor = Color.White;
            }
            shape.Size          = new SizeF(400, 400);
            imageNode.Node.Text = imageNode.LabledVertex.Opcode.ToString() + " index:" + imageNode.LabledVertex.Index;
            if (imageNode.LabledVertex is CompoundedLabeledVertex)
            {
                imageNode.Node.Text += "multi";
            }
            imageNode.Node.Selected   += Node_Selected;
            imageNode.Node.UnSelected += Node_UnSelected;
        }
Beispiel #10
0
 /// <summary>
 /// Advance the enumerator to the next GoObject in the whole collection of layers of GoObjects.
 /// </summary>
 /// <returns>True if there is a next GoObject; false if it has finished iterating over the collection.</returns>
 public bool MoveNext()
 {
     if (myEnumeratorValid)
     {
         if (myEnumerator.MoveNext())
         {
             return(true);
         }
         myEnumeratorValid = false;
     }
     checked
     {
         if (myForward)
         {
             while (myIndex + 1 < myArray.Count)
             {
                 myIndex++;
                 GoLayer goLayer = myArray[myIndex];
                 myEnumerator      = goLayer.GetEnumerator();
                 myEnumeratorValid = true;
                 if (myEnumerator.MoveNext())
                 {
                     return(true);
                 }
             }
             return(false);
         }
         while (myIndex - 1 >= 0)
         {
             myIndex--;
             GoLayer goLayer2 = myArray[myIndex];
             myEnumerator      = goLayer2.Backwards;
             myEnumeratorValid = true;
             if (myEnumerator.MoveNext())
             {
                 return(true);
             }
         }
         return(false);
     }
 }
            public int Compare(GoObject a, GoObject b)
            {
                if (a == null || b == null || a == b)
                {
                    return(0);
                }
                if (a.Layer != b.Layer)
                {
                    int num  = myLayers.IndexOf(a.Layer);
                    int num2 = myLayers.IndexOf(b.Layer);
                    if (num < num2)
                    {
                        return(-1);
                    }
                    if (num > num2)
                    {
                        return(1);
                    }
                }
                if (a.Layer == null)
                {
                    return(0);
                }
                GoLayer layer = a.Layer;
                int     num3  = layer.IndexOf(a.TopLevelObject);
                int     num4  = layer.IndexOf(b.TopLevelObject);

                if (num3 < num4)
                {
                    return(-1);
                }
                if (num3 > num4)
                {
                    return(1);
                }
                return(AFirst(a.TopLevelObject, a, b));
            }
Beispiel #12
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);
        }
Beispiel #13
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
             { }
         }
     }
 }
Beispiel #14
0
        /// <summary>
        /// Change the <see cref="P:Northwoods.Go.GoObject.Parent" /> of an object to be the common subgraph that
        /// contains two given objects, or if there is no such subgraph, add the object to the given layer.
        /// </summary>
        /// <param name="obj">the <see cref="T:Northwoods.Go.GoObject" /> to reparent</param>
        /// <param name="child1">an object that may belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param>
        /// <param name="child2">another object that may belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param>
        /// <param name="behind">whether to add the <paramref name="obj" /> at the beginning of the list
        /// of the subgraph's children (thus behind all other subgraph children), or at the end of the list
        /// (thus appearing in front of all the other subgraph children)</param>
        /// <param name="layer">
        /// the <see cref="T:Northwoods.Go.GoLayer" /> to which the <paramref name="obj" /> should be added,
        /// if there is no common parent <see cref="T:Northwoods.Go.GoSubGraphBase" /> for <paramref name="child1" /> and
        /// <paramref name="child2" />
        /// </param>
        /// <remarks>
        /// All of the arguments to this method should be non-null.
        /// </remarks>
        public static void ReparentToCommonSubGraph(GoObject obj, GoObject child1, GoObject child2, bool behind, GoLayer layer)
        {
            GoSubGraphBase a        = FindParentSubGraph(child1);
            GoSubGraphBase b        = FindParentSubGraph(child2);
            GoObject       goObject = GoObject.FindCommonParent(a, b);

            while (goObject != null && !(goObject is GoSubGraphBase))
            {
                goObject = goObject.Parent;
            }
            GoSubGraphBase goSubGraphBase = goObject as GoSubGraphBase;

            if (obj.Parent == goSubGraphBase && obj.Layer != null)
            {
                return;
            }
            if (obj.Parent == null && obj.Layer == null)
            {
                if (goSubGraphBase != null)
                {
                    if (behind)
                    {
                        goSubGraphBase.InsertBefore(null, obj);
                    }
                    else
                    {
                        goSubGraphBase.InsertAfter(null, obj);
                    }
                }
                else
                {
                    layer.Add(obj);
                }
            }
            else
            {
                GoCollection goCollection = new GoCollection();
                goCollection.Add(obj);
                if (goSubGraphBase != null)
                {
                    goSubGraphBase.AddCollection(goCollection, reparentLinks: false);
                }
                else
                {
                    layer.AddCollection(goCollection, reparentLinks: false);
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// Make sure each link, either directly in the given collection, or connected to the nodes in
        /// the given collection, belong to the appropriate <see cref="T:Northwoods.Go.GoSubGraphBase" />.
        /// </summary>
        /// <param name="coll"></param>
        /// <param name="behind">whether to add the <paramref name="coll" /> at the beginning of the list
        /// of the subgraph's children (thus behind all other subgraph children), or at the end of the list
        /// (thus appearing in front of all the other subgraph children)</param>
        /// <param name="layer">the <see cref="T:Northwoods.Go.GoLayer" /> for links whose ports do not both belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param>
        /// <remarks>
        /// This calls <see cref="M:Northwoods.Go.GoSubGraphBase.ReparentToCommonSubGraph(Northwoods.Go.GoObject,Northwoods.Go.GoObject,Northwoods.Go.GoObject,System.Boolean,Northwoods.Go.GoLayer)" /> for each <see cref="T:Northwoods.Go.IGoLink" /> in the
        /// <paramref name="coll" /> collection, or for each <see cref="T:Northwoods.Go.IGoLink" /> connected to each <see cref="T:Northwoods.Go.IGoNode" />
        /// in the <paramref name="coll" /> collection.
        /// </remarks>
        public static void ReparentAllLinksToSubGraphs(IGoCollection coll, bool behind, GoLayer layer)
        {
            GoCollection goCollection = new GoCollection();

            foreach (GoObject item in coll)
            {
                goCollection.Add(item);
            }
            foreach (GoObject item2 in goCollection)
            {
                IGoNode goNode = item2 as IGoNode;
                if (goNode != null)
                {
                    foreach (IGoLink link in goNode.Links)
                    {
                        if (link != null && link.FromPort != null && link.ToPort != null)
                        {
                            ReparentToCommonSubGraph(link.GoObject, link.FromPort.GoObject, link.ToPort.GoObject, behind, layer);
                        }
                    }
                }
                else
                {
                    IGoPort goPort = item2 as IGoPort;
                    if (goPort != null)
                    {
                        foreach (IGoLink link2 in goPort.Links)
                        {
                            if (link2 != null && link2.FromPort != null && link2.ToPort != null)
                            {
                                ReparentToCommonSubGraph(link2.GoObject, link2.FromPort.GoObject, link2.ToPort.GoObject, behind, layer);
                            }
                        }
                    }
                    else
                    {
                        IGoLink goLink = item2 as IGoLink;
                        if (goLink != null && goLink.FromPort != null && goLink.ToPort != null)
                        {
                            ReparentToCommonSubGraph(goLink.GoObject, goLink.FromPort.GoObject, goLink.ToPort.GoObject, behind, layer);
                        }
                    }
                }
            }
        }
Beispiel #16
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;
        }
 public RouterSource(GoLayer layer)
 {
     goLayer = layer;
 }