예제 #1
0
        /// <summary>
        /// Given a graph, rewrite is given the heuristics of this pattern class
        /// </summary>
        /// <param name="graph"></param>
        /// <returns></returns>
        public List <SnapshotNode> RewriteFromPattern(List <SnapshotNode> graph)
        {
            List <SnapshotNode> n = new List <SnapshotNode>();

            foreach (SnapshotNode c in graph)
            {
                n.Add(c);
            }
            foreach (SnapshotNode node in n)
            {
                if (node.Type == SnapshotNodeType.Function)
                {
                    string[] functionQualifers = node.Content.Split(';');
                    switch (functionQualifers[1])
                    {
                    case "CircleBy3Points":
                        SnapshotNode funcWrap = new SnapshotNode((uint)node.Id * 101, SnapshotNodeType.CodeBlock, "def CircleBy3Points(p1, p2, p3) \n{\n    temp1 = p3.X - p1.X;\n    temp2 = p3.Y - p1.Y;\n    temp3 = p3.Z - p1.Z;\n    temp4 = p2.X - p1.X;\n    temp5 = p2.Y - p1.Y;\n    temp6 = p2.Z - p1.Z;\n    temp7 = Vector.ByCoordinates(temp1, temp2, temp3);\n    temp8 = Vector.ByCoordinates(temp4, temp5, temp6);\n    centerX = (p1.X + p2.X + p3.X) / 3;\n    centerY = (p1.Y + p2.Y + p3.Y) / 3;\n    centerZ = (p1.Z + p2.Z + p3.Z) / 3;\n    centre = Point.ByCoordinates(centerX, centerY, centerZ);\n    radius = centre.DistanceTo(p1);return = Circle.ByCenterPointRadius(centre, radius,temp8.Cross(temp7));\n}");
                        graph.Add(funcWrap);
                        break;

                    default: break;
                    }
                }
            }
            return(graph);
        }
예제 #2
0
 internal CodeBlockNode(IGraphController graphController, SnapshotNode snapshotNode)
     : base(graphController, NodeType.CodeBlock)
 {
     this.Caption = string.Empty;
     this.Text = snapshotNode.Content;
     string error;
     ErrorType errorType;
     AmendInputOutputSlots(out error, out errorType);
 }
예제 #3
0
        private static SnapshotNode SnapshotNodeProcess(string p)
        {
            uint              ID;
            SnapshotNodeType  t;
            string            Content;
            List <Connection> inputs  = new List <Connection>();
            List <Connection> outputs = new List <Connection>();

            string[] a = p.Split(IDMarker);
            ID = uint.Parse(a[0]);
            string[] b = a[1].Split(TypeMarker);
            switch (b[0])
            {
            case "Identifier": t = SnapshotNodeType.Identifier; break;

            case "Literal": t = SnapshotNodeType.Literal; break;

            case "Function": t = SnapshotNodeType.Function; break;

            case "CodeBlock": t = SnapshotNodeType.CodeBlock; break;

            case "Array": t = SnapshotNodeType.Array; break;

            default: t = SnapshotNodeType.None; break;
            }
            string[] c = b[1].Split(ContentLengthMarker);
            string[] d = c[1].Split(ContentEndMarker);
            if (Int32.Parse(c[0]) == 0)
            {
                Content = string.Empty;
            }
            else
            {
                Content = d[0];
            }
            string[] e = d[1].Split(ConnectionListEndMarker);
            inputs  = ProcessConnectionLists(e[0]);
            outputs = ProcessConnectionLists(e[1]);
            SnapshotNode ssn = new SnapshotNode(ID, t, Content);

            ssn.InputList  = inputs;
            ssn.OutputList = outputs;
            return(ssn);
        }
예제 #4
0
        /// <summary>
        /// Given a graph, rewrite is given the heuristics of this pattern class
        /// </summary>
        /// <param name="graph"></param>
        /// <returns></returns>
        public List <SnapshotNode> RewriteFromPattern(List <SnapshotNode> graph)
        {
            List <SnapshotNode> n = new List <SnapshotNode>();

            foreach (SnapshotNode c in graph)
            {
                n.Add(c);
            }
            foreach (SnapshotNode node in n)
            {
                if (node.Type == SnapshotNodeType.Function)
                {
                    string[] functionQualifers = node.Content.Split(';');
                    switch (functionQualifers[1])
                    {
                    case "Math.Sin":
                    case "Math.Cos":
                    case "Math.Tan":
                        SnapshotNode      ssn = new SnapshotNode((uint)(node.Id * 100), node.Type, "Math.dll;Math.RadiansToDegrees; ");
                        List <Connection> inp = new List <Connection>();
                        foreach (Connection c in node.InputList)
                        {
                            inp.Add(c);
                        }
                        ssn.InputList  = inp;
                        ssn.OutputList = new List <Connection>();
                        graph.Add(ssn);
                        Connection connection = new Connection();
                        connection.OtherNode  = ssn.Id;
                        connection.LocalIndex = 0;
                        connection.OtherIndex = 0;
                        int num = graph.IndexOf(node);
                        graph[num].InputList.Clear();
                        graph[num].InputList.Add(connection);
                        break;

                    default: break;
                    }
                }
            }
            return(graph);
        }
예제 #5
0
 /// <summary>
 /// Given a graph, rewrite is given the heuristics of this pattern class
 /// </summary>
 /// <param name="graph"></param>
 /// <returns></returns>
 public List<SnapshotNode> RewriteFromPattern(List<SnapshotNode> graph)
 {
     List<SnapshotNode> n=new List<SnapshotNode>();
     foreach (SnapshotNode c in graph)
                         n.Add(c);
     foreach (SnapshotNode node in n)
     {
         if (node.Type == SnapshotNodeType.Function)
         {
             string[] functionQualifers = node.Content.Split(';');
             switch (functionQualifers[1])
             {
                 case "Math.Sin":
                 case "Math.Cos":
                 case "Math.Tan":
                     SnapshotNode ssn = new SnapshotNode((uint)(node.Id * 100), node.Type, "Math.dll;Math.RadiansToDegrees; ");
                     List<Connection> inp = new List<Connection>();
                     foreach (Connection c in node.InputList)
                         inp.Add(c);
                     ssn.InputList = inp;
                     ssn.OutputList = new List<Connection>();
                     graph.Add(ssn);
                     Connection connection = new Connection();
                     connection.OtherNode = ssn.Id;
                     connection.LocalIndex = 0;
                     connection.OtherIndex = 0;
                     int num = graph.IndexOf(node);
                     graph[num].InputList.Clear();
                     graph[num].InputList.Add(connection);
                     break;
                 default: break;
             }
         }
     }
     return graph;
 }
예제 #6
0
        public bool CreateCodeblockNode(SnapshotNode ssn)
        {
            graph.AddNode(new Block(ssn.Content, ssn.Id, ssn.Assignments));
            RewriteCodeBlock(graph);

            return true;
        }
        public override string ToScript()
        {
            string result = string.Empty;

            #region StaticFunctrionPrinting
            if (((Func)func).isStatic)
            {
                if (null != func)
                {
                    if (((Func)func).isRange)
                    {
                    }
                    else
                    {
                        result += func.ToScript();
                    }
                }
                #region Range
                if (((Func)func).isRange)
                {
                    if (null != parameters)
                    {
                        var sortedDict = (from entry in parameters orderby entry.Key ascending select entry)
                                         .ToDictionary(pair => pair.Key, pair => pair.Value);
                        IEnumerable iter  = sortedDict;
                        int         count = 0;
                        if (((Func)func).replicationGuide.Equals("") || ((Func)func).replicationGuide == null)
                        {
                            foreach (Node node in sortedDict.Values)
                            {
                                string arg = string.Empty;
                                count++;
                                if (node != null)
                                {
                                    if (node is Block)
                                    {
                                        arg = (node as Block).LHS;
                                    }
                                    else
                                    {
                                        // TODO Jun: Implement a codeblock ToScript function such that it returns the contents, not the name
                                        arg = node.ToScript();
                                    }
                                    if (count == 3)
                                    {
                                        if (((Func)func).argTypeRange == 0)
                                        {
                                            result += arg + "..";
                                        }
                                        else if (((Func)func).argTypeRange == 1)
                                        {
                                            result += "~" + arg + "..";
                                        }
                                        else
                                        {
                                            result += "#" + arg + "..";
                                        }
                                    }
                                    else
                                    {
                                        result += arg + "..";
                                    }
                                }
                                else
                                {
                                    if (count == 3)
                                    {
                                        ;
                                    }
                                    else
                                    {
                                        result += ProtoCore.DSDefinitions.Keyword.Null + "..";
                                    }
                                }
                            }
                        }
                        else
                        {
                            string[] repGuideforParam = ((Func)func).replicationGuide.Split('¡');
                            int      i = 0;
                            foreach (Node node in sortedDict.Values)
                            {
                                string[] repGuideForNode = repGuideforParam[i++].Split(',');
                                string   arg             = string.Empty;
                                count++;
                                if (node != null)
                                {
                                    if (node is Block)
                                    {
                                        arg = (node as Block).LHS;
                                    }
                                    else
                                    {
                                        // TODO Jun: Implement a codeblock ToScript function such that it returns the contents, not the name
                                        arg = node.ToScript();
                                    }
                                    if (count == 3)
                                    {
                                        if (((Func)func).argTypeRange == 0)
                                        {
                                            result += arg;// +
                                            for (int j = 0; j < repGuideForNode.Length - 1; j++)
                                            {
                                                result += "<" + repGuideForNode[j] + ">";
                                            }
                                            result += "..";
                                            if (i == repGuideforParam.Length - 1)
                                            {
                                                break;
                                            }
                                        }
                                        else if (((Func)func).argTypeRange == 1)
                                        {
                                            result += "~" + arg;// +"..";
                                            for (int j = 0; j < repGuideForNode.Length - 1; j++)
                                            {
                                                result += "<" + repGuideForNode[j] + ">";
                                            }
                                            result += "..";
                                            if (i == repGuideforParam.Length - 1)
                                            {
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            result += "#" + arg;// +"..";
                                            for (int j = 0; j < repGuideForNode.Length - 1; j++)
                                            {
                                                result += "<" + repGuideForNode[j] + ">";
                                            }
                                            result += "..";
                                            if (i == repGuideforParam.Length - 1)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        result += arg;// +"..";
                                        for (int j = 0; j < repGuideForNode.Length - 1; j++)
                                        {
                                            result += "<" + repGuideForNode[j] + ">";
                                        }
                                        result += "..";
                                    }
                                }
                                else
                                {
                                    if (count == 3)
                                    {
                                        ;
                                    }
                                    else
                                    {
                                        result += ProtoCore.DSDefinitions.Keyword.Null + "..";
                                    }
                                }
                            }
                        }
                        result = result.Substring(0, result.Length - 2);
                    }
                }
                #endregion
                else
                {
                    result += "(";
                    if (null != parameters)
                    {
                        var sortedDict = (from entry in parameters orderby entry.Key ascending select entry)
                                         .ToDictionary(pair => pair.Key, pair => pair.Value);
                        IEnumerable iter = sortedDict;

                        string[] repGuideforParam = ((Func)func).replicationGuide.Split(GraphToDSCompiler.Constants.ReplicationGuideDelimiter);
                        int      n = 0;
                        foreach (Node node in sortedDict.Values)
                        {
                            string arg = string.Empty;
                            if (node != null)
                            {
                                if (node is Block)
                                {
                                    arg = (node as Block).LHS + " ";
                                }
                                else
                                {
                                    arg = node.ToScript() + " ";
                                }

                                result += " " + arg;

                                if (n < repGuideforParam.Length)
                                {
                                    result += SnapshotNode.ParseReplicationGuideText(repGuideforParam[n]);
                                }

                                result += ",";
                            }
                            else
                            {
                                result += " " + ProtoCore.DSDefinitions.Keyword.Null + ",";
                            }
                            n++;
                        }
                    }
                    if (parameters.Count > 0)
                    {
                        result = result.Substring(0, result.Length - 1);
                    }
                    result += " )";
                }
            }
            #endregion

            else
            {
                if (null != func)
                {
                    if (null != parameters)
                    {
                        var sortedDict = (from entry in parameters orderby entry.Key ascending select entry)
                                         .ToDictionary(pair => pair.Key, pair => pair.Value);
                        IEnumerable iter  = sortedDict;
                        int         count = 0;
                        if (string.IsNullOrEmpty(((Func)func).replicationGuide))
                        {
                            foreach (Node node in sortedDict.Values)
                            {
                                string arg = string.Empty;
                                count++;
                                if (node != null)
                                {
                                    if (count == 1)
                                    {
                                        result += node.ToScript() + "." + func.ToScript();
                                        if (!((Func)func).isProperty)
                                        {
                                            result += "(";
                                        }
                                    }
                                    else
                                    {
                                        if (node is Block)
                                        {
                                            arg = (node as Block).LHS + " ";
                                        }
                                        else
                                        {
                                            arg = node.ToScript() + " ";
                                        }
                                        result += " " + arg + ",";
                                    }
                                }
                                else
                                {
                                    if (count == 1)
                                    {
                                        result += Constants.kwTempNull + "." + func.ToScript();
                                        if (!((Func)func).isProperty)
                                        {
                                            result += "(";
                                        }
                                    }
                                    else
                                    {
                                        result += " " + ProtoCore.DSDefinitions.Keyword.Null + ",";
                                    }
                                }
                            }
                        }
                        else
                        {
                            string[] repGuideforParam = ((Func)func).replicationGuide.Split(GraphToDSCompiler.Constants.ReplicationGuideDelimiter);
                            int      i = 0;
                            int      n = 0;
                            foreach (Node node in sortedDict.Values)
                            {
                                string arg = string.Empty;
                                count++;
                                string[] repGuideForNode = repGuideforParam[i++].Split(',');
                                if (node != null)
                                {
                                    if (count == 1)
                                    {
                                        result += node.ToScript();
                                        result += SnapshotNode.ParseReplicationGuideText(repGuideforParam[n]);
                                        result += "." + func.ToScript() + "(";
                                    }
                                    else
                                    {
                                        if (node is Block)
                                        {
                                            arg = (node as Block).LHS + " ";
                                        }
                                        else
                                        {
                                            arg = node.ToScript() + " ";
                                        }
                                        result += " " + arg;
                                        result += SnapshotNode.ParseReplicationGuideText(repGuideforParam[n]);
                                        result += ",";

                                        if (i == repGuideforParam.Length - 1)
                                        {
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    if (count == 1)
                                    {
                                        result += Constants.kwTempNull + "." + func.ToScript() + "(";
                                    }
                                    else
                                    {
                                        result += " " + ProtoCore.DSDefinitions.Keyword.Null + ",";
                                    }
                                }
                                n++;
                            }
                        }
                        if (count == 0)
                        {
                            result += func.ToScript();
                        }
                    }

                    if (result.EndsWith(","))
                    {
                        result = result.Substring(0, result.Length - 1);
                    }

                    if (!((Func)func).isProperty)
                    {
                        result += " )";
                    }
                }
            }
            return(result);
        }
        public override string ToScript()
        {
            string result = string.Empty;

            result += "(";
            if (((Operator)op).replicationGuide.Equals("") || ((Operator)op).replicationGuide == null)
            {
                // Handle left
                string code = string.Empty;
                if (null != left)
                {
                    if (left is Block)
                    {
                        result += (left as Block).LHS + " ";
                    }
                    else
                    {
                        // TODO Jun: Implement a codeblock ToScript function such that it returns the contents, not the name
                        result += left.ToScript() + " ";
                    }
                }
                else
                {
                    result += ProtoCore.DSDefinitions.Keyword.Null + " ";
                }

                // Handle operator
                if (null != op)
                {
                    result += op.ToScript();
                }

                //Handle right
                if (null != right)
                {
                    if (right is Block)
                    {
                        result += (right as Block).LHS + " ";
                    }
                    else
                    {
                        result += right.ToScript() + " ";
                    }
                }
                else
                {
                    result += " " + ProtoCore.DSDefinitions.Keyword.Null;
                }
            }
            else
            {
                string[] repGuideforParam     = ((Operator)op).replicationGuide.Split('¡');
                string[] repGuideForLeftNode  = repGuideforParam[0].Split(',');
                string[] repGuideForRightNode = repGuideforParam[1].Split(',');
                if (null != left)
                {
                    if (left is Block)
                    {
                        result += (left as Block).LHS + " ";
                    }
                    else
                    {
                        result += left.ToScript() + " ";
                    }
                    //for (int j = 0; j < repGuideForLeftNode.Length - 1; j++)
                    //    result += "<" + repGuideForLeftNode[j] + ">";

                    result += SnapshotNode.ParseReplicationGuideText(repGuideforParam[0]);

                    result += " ";
                }
                else
                {
                    result += ProtoCore.DSDefinitions.Keyword.Null + " ";
                }
                if (null != op)
                {
                    result += op.ToScript();
                }
                if (null != right)
                {
                    if (right is Block)
                    {
                        result += (right as Block).LHS + " ";
                    }
                    else
                    {
                        result += right.ToScript() + " ";
                    }
                    //for (int j = 0; j < repGuideForRightNode.Length - 1; j++)
                    //    result += "<" + repGuideForRightNode[j] + ">";


                    result += SnapshotNode.ParseReplicationGuideText(repGuideforParam[1]);

                    result += " ";
                }
                else
                {
                    result += " " + ProtoCore.DSDefinitions.Keyword.Null;
                }
            }
            return(result + ")");
        }
예제 #9
0
 private static SnapshotNode SnapshotNodeProcess(string p)
 {
     uint ID;
     SnapshotNodeType t;
     string Content;
     List<Connection> inputs = new List<Connection>();
     List<Connection> outputs = new List<Connection>();
     string[] a = p.Split(IDMarker);
     ID = uint.Parse(a[0]);
     string[] b = a[1].Split(TypeMarker);
     switch (b[0])
     {
         case "Identifier": t = SnapshotNodeType.Identifier; break;
         case "Literal": t = SnapshotNodeType.Literal; break;
         case "Function": t = SnapshotNodeType.Function; break;
         case "CodeBlock": t = SnapshotNodeType.CodeBlock; break;
         case "Array": t = SnapshotNodeType.Array; break;
         default: t = SnapshotNodeType.None; break;
     }
     string[] c = b[1].Split(ContentLengthMarker);
     string[] d = c[1].Split(ContentEndMarker);
     if (Int32.Parse(c[0]) == 0) Content = string.Empty;
     else Content = d[0];
     string[] e = d[1].Split(ConnectionListEndMarker);
     inputs = ProcessConnectionLists(e[0]);
     outputs = ProcessConnectionLists(e[1]);
     SnapshotNode ssn = new SnapshotNode(ID, t, Content);
     ssn.InputList = inputs;
     ssn.OutputList = outputs;
     return ssn;
 }
예제 #10
0
 public void TestDeltaExecution03()
 {
     //===========================================================================
     // Creates:
     //      driver  node a = 10
     //      driver node b= 20
     //      and using '+' operator node and assign it to idetifier
     //===========================================================================
     ILiveRunner liveRunner = new ProtoScript.Runners.Obsolete.LiveRunner();
     //===========================================================================
     // Build the driver node a=10
     //===========================================================================
     GraphToDSCompiler.SynchronizeData data = new GraphToDSCompiler.SynchronizeData();
     uint uidDriver1 = 1;
     uint uidDriver2 = 2;
     uint uidOp1 = 3;
     uint uidIdent1 = 4;
     Connection k1 = new Connection();
     k1.LocalIndex = 0;// output slot
     k1.OtherIndex = 0;// input slot
     k1.OtherNode = uidOp1;
     k1.LocalName = "a";
     Connection k2 = new Connection();
     k2.LocalIndex = 0;
     k2.OtherIndex = 1;
     k2.OtherNode = uidOp1;
     k2.LocalName = "b";
     Connection k4 = new Connection();
     k4.LocalIndex = 0;
     k4.OtherIndex = 0;
     k4.OtherNode = uidDriver1;
     Connection k5 = new Connection();
     k5.LocalIndex = 1;
     k5.OtherIndex = 0;
     k5.OtherNode = uidDriver2;
     Connection k6 = new Connection();
     k6.LocalIndex = 0;
     k6.OtherIndex = 0;
     k6.OtherNode = uidIdent1;
     Connection k7 = new Connection();
     k7.LocalIndex = 0;
     k7.OtherIndex = 0;
     k7.OtherNode = uidOp1;
     SnapshotNode n1 = new SnapshotNode(uidDriver1, SnapshotNodeType.CodeBlock, "a=10;");
     n1.OutputList.Add(k1);
     SnapshotNode n2 = new SnapshotNode(uidDriver2, SnapshotNodeType.CodeBlock, "b=20;");
     n2.OutputList.Add(k2);
     SnapshotNode n3 = new SnapshotNode(uidOp1, SnapshotNodeType.Function, ";+;double,double;temp");
     n3.InputList.Add(k4);
     n3.InputList.Add(k5);
     n3.OutputList.Add(k6);
     SnapshotNode n4 = new SnapshotNode(uidIdent1, SnapshotNodeType.Identifier, "A");
     n4.InputList.Add(k7);
     data.AddedNodes.Add(n1);
     data.AddedNodes.Add(n2);
     data.AddedNodes.Add(n3);
     data.AddedNodes.Add(n4);
     //===========================================================================
     // Compile the current graph
     //===========================================================================
     liveRunner.UpdateGraph(data);
     //===========================================================================
     // Verify the value of Identifier
     //===========================================================================
     ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.QueryNodeValue(uidIdent1);
     Assert.IsTrue(mirror.GetData().GetStackValue().opdata == 30);
 }
예제 #11
0
 public void TestDeltaExecution01()
 {
     //===========================================================================
     // Creates:
     //      a = 10
     //
     // Adds:
     //      b = 20
     //===========================================================================
     ILiveRunner liveRunner = new ProtoScript.Runners.Obsolete.LiveRunner();
     //===========================================================================
     // Build the first snapshot nodes a = 10
     //===========================================================================
     GraphToDSCompiler.SynchronizeData data = new GraphToDSCompiler.SynchronizeData();
     uint uidIdent = 1;
     uint uidLiteral = 2;
     Connection k1 = new Connection();
     k1.LocalIndex = 0;
     k1.OtherIndex = 0;
     k1.OtherNode = uidLiteral;
     Connection k2 = new Connection();
     k2.LocalIndex = 0;
     k2.OtherIndex = 0;
     k2.OtherNode = uidIdent;
     SnapshotNode n1 = new SnapshotNode(uidIdent, SnapshotNodeType.Identifier, "a");
     n1.InputList.Add(k1);
     SnapshotNode n2 = new SnapshotNode(uidLiteral, SnapshotNodeType.Literal, "10");
     n2.OutputList.Add(k2);
     data.AddedNodes.Add(n1);
     data.AddedNodes.Add(n2);
     //===========================================================================
     // Compile the current graph
     //===========================================================================
     liveRunner.UpdateGraph(data);
     //===========================================================================
     // Build the first snapshot nodes b = 10
     //===========================================================================
     uint uidIdent2 = 10;
     uint uidLiteral2 = 20;
     data = new GraphToDSCompiler.SynchronizeData();
     k1 = new Connection();
     k1.LocalIndex = 0;
     k1.OtherIndex = 0;
     k1.OtherNode = uidLiteral2;
     k2 = new Connection();
     k2.LocalIndex = 0;
     k2.OtherIndex = 0;
     k2.OtherNode = uidIdent2;
     n1 = new SnapshotNode(uidIdent2, SnapshotNodeType.Identifier, "b");
     n1.InputList.Add(k1);
     n2 = new SnapshotNode(uidLiteral2, SnapshotNodeType.Literal, "20");
     n2.OutputList.Add(k2);
     data.AddedNodes.Add(n1);
     data.AddedNodes.Add(n2);
     //===========================================================================
     // Compile the current graph and added graph
     //===========================================================================
     liveRunner.UpdateGraph(data);
     //===========================================================================
     // Verify the value of 'a'
     //===========================================================================
     ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.QueryNodeValue(uidIdent);
     Assert.IsTrue(mirror.GetData().GetStackValue().opdata == 10);
     //===========================================================================
     // Verify the value of 'b'
     //===========================================================================
     mirror = liveRunner.QueryNodeValue(uidIdent2);
     Assert.IsTrue(mirror.GetData().GetStackValue().opdata == 20);
 }
예제 #12
0
        /// <summary>
        ///  This function updates the nodes of a codeblock that was split given the original codeblocks' uid
        /// </summary>
        /// <param name="codeblock"></param>
        private void UpdateCodeBlockNodeDirtyFlags(SnapshotNode codeblock)
        {
            Validity.Assert(codeblock.Type == SnapshotNodeType.CodeBlock);
            string name = string.Empty;

            // The codeblock is multiline if its uid exisits in the codeblock map
            // A better approach maybe the IDE flagging this as a snapshot node property

            // Comment Jun:
            // If its a single line codeblock, then just get its name and update the flag
            // If its a multi-line codeblock, then get all the associated split codeblocks, get all the names, and update the flag

            bool isMultiLine = codeBlockUIDMap.ContainsKey(codeblock.Id);
            if (isMultiLine)
            {
                // This function will nto be necessary if the snapshot node stored the number of outputslots as a property
                int outputSlots = codeblock.GetNumOutputs();
                for (int index = 0; index < outputSlots; index++)
                {
                    name = GetVarName(codeblock.Id, index, SnapshotNodeType.CodeBlock);
                    if (name != null && name.Length > 0)
                    {
                        if (ExecutionFlagList.Keys.Contains(name))
                        {
                            ExecutionFlagList[name] = true;
                        }
                    }
                }
            }
            else
            {
                name = GetVarName(codeblock.Id);
                if (name != null && name.Length > 0)
                {
                    if (ExecutionFlagList.Keys.Contains(name))
                    {
                        ExecutionFlagList[name] = true;
                    }
                }
            }
        }
예제 #13
0
        /**/
        public List<uint> ConnectionToUID(List<Connection> input)
        {
            List<uint> result = new List<uint>();
            foreach (Connection inputConnection in input)
            {
                result.Add(inputConnection.OtherNode);
            }
            return result;
        }

        /*Tron: Use for node to code function
         *For each connected component of the graph, generate a respective string of code
         */
        public List<SnapshotNode> ToCode(AST graph, GraphCompiler originalGC, List<SnapshotNode> inputs)
        {
            List<SnapshotNode> result = new List<SnapshotNode>();

            List<Node> li = TopSort.sort(graph);
            tguid = 20000;
            List<string> listIslands = new List<string>();
            List<Node> islandNodes = new List<Node>();
            int countIslands = 0;
            statementList = new AST();
            ModifiedStmtGuidList.Clear();
            List<string> importIslands = new List<string>();
            IEnumerable iter = li;
            List<Node> islandNodeList = new List<Node>();
            //List<List<Node>> listing = new List<List<Node>>();
            List<Node> listing = new List<Node>();
            foreach (Node node in iter)
            {
                if (node != null)
                {
                    if (node is ImportNode)
                    {
                        importIslands.Add(node.ToScript() + ProtoCore.DSASM.Constants.termline);
                    }
                    else if (node.IsIsland)
                    {
                        countIslands++;
                        if (node is ArrayNode)
                        {
                            BuildArrayNodeStatement(node, statementList);
                            if (!islandNodes.Contains(node))
                                islandNodes.Add(node);
                            string island = statementList.GetNode(node.Guid).ToScript() + ProtoCore.DSASM.Constants.termline;
                            if (!listIslands.Contains(island))
                                listIslands.Add(island);
                        }
                        else if (node is LiteralNode)
                        {
                            BuildLiteralNodeStatement(node, statementList);
                            string island = statementList.GetNode(node.Guid).ToScript() + ProtoCore.DSASM.Constants.termline;
                            if (!listIslands.Contains(island))
                                listIslands.Add(island);
                        }
                        else if (node is Func)
                        {
                            BuildFunctionCallStatement(node, statementList);
                            string island = statementList.GetNode(node.Guid).ToScript() + ProtoCore.DSASM.Constants.termline;
                            if (!listIslands.Contains(island))
                                listIslands.Add(island);
                        }
                        else if (node is Operator)
                        {
                            BuildOperatorStatement(node, statementList);
                            string island = statementList.GetNode(node.Guid).ToScript() + ProtoCore.DSASM.Constants.termline;
                            if (!listIslands.Contains(island))
                                listIslands.Add(island);
                        }
                        else if (node is Block)
                        {
                            BuildBlockStatement(node, statementList);
                            islandNodes.Add(node);
                            //string island = statementList.GetNode(node.Guid).ToScript() + ProtoCore.DSASM.Constants.termline;
                            //if (!listIslands.Contains(island))
                              //  listIslands.Add(island);
                        }
                        else if (node is IdentNode)
                        {
                            // comment Jun:
                            // An island identifier node is handled by emitting a null as its rhs
                            statementList.AddNode(node);
                            string contents = statementList.GetNode(node.Guid).ToScript() + "=" + ProtoCore.DSASM.Literal.Null + ProtoCore.DSASM.Constants.termline;
                            listIslands.Add(contents);
                        }
                        else
                        {
                            statementList.AddNode(node);
                            string island = node.ToScript() + ProtoCore.DSASM.Constants.termline;
                            if (!listIslands.Contains(island))
                                listIslands.Add(island);
                        }
                        islandNodeList.Add(node);
                        listing = listing.ToList().Union<Node>(BuildStatement(node, statementList)).ToList();
                        HandleNewNode(node);
                    }
                    else if (node.IsLeaf)
                    {
                        if (node is ArrayNode)
                        {
                            BuildArrayNodeStatement(node, statementList);
                        }
                        else if (node is LiteralNode)
                        {
                            BuildLiteralNodeStatement(node, statementList);
                        }
                        else if (node is Func)
                        {
                            BuildFunctionCallStatement(node, statementList);
                        }
                        else if (node is Operator)
                        {
                            BuildOperatorStatement(node, statementList);
                        }
                        else if (node is Block)
                        {
                            BuildBlockStatement(node, statementList);
                        }
                        else if (node is IdentNode)
                        {
                            statementList.AddNode(node);
                            string contents = statementList.GetNode(node.Guid).ToScript() + "=" + ProtoCore.DSASM.Literal.Null + ProtoCore.DSASM.Constants.termline;
                            listIslands.Add(contents);
                        }
                        HandleNewNode(node);
                    }
                    else if (node.IsRoot && !node.IsIsland)
                    {
                        if (node is Operator)
                        {
                            BuildOperatorStatement(node, statementList);
                        }
                        else if (node is Func)
                        {
                            BuildFunctionCallStatement(node, statementList);
                        }
                        else if (node is Block)
                        {
                            BuildBlockStatement(node, statementList);
                        }
                        //liststat = BuildStatement(node, statementList);
                        //finalScript=finalScript.Union(BuildStatement(node, statementList)).ToList();
                        
                        //comment out for NodeToCode function
                        //listing.Add(BuildStatement(node, statementList));
                        listing = BuildStatement(node, statementList);
                        HandleNewNode(node);
                    }
                    else if (node is Operator)
                    {
                        BuildOperatorStatement(node, statementList);
                        HandleNewNode(node);
                    }
                    else if (node is Func)
                    {
                        BuildFunctionCallStatement(node, statementList);
                        HandleNewNode(node);
                    }
                    else if (node is ArrayNode)
                    {
                        BuildArrayNodeStatement(node, statementList);
                        HandleNewNode(node);
                    }
                    else if (node is LiteralNode)
                    {
                        BuildLiteralNodeStatement(node, statementList);
                        HandleNewNode(node);
                    }
                    else if (node is Block)
                    {
                        BuildBlockStatement(node, statementList);
                        listing = BuildStatement(node, statementList);
                        HandleNewNode(node);
                    }
                }
            }
            StringBuilder builder = new StringBuilder();
            foreach (string island in importIslands)// Loop through all strings
            {
                builder.Append(island);             // Append string to StringBuilder
            }
            foreach (string island in listIslands)  // Loop through all strings
            {
                builder.Append(island);             // Append string to StringBuilder
            }

            /*N2C*/
            #region get connected components of the graph
            List<Node> nodeToCodeInputList = new List<Node>();
            List<List<Node>> listingAlternate = new List<List<Node>>();
            List<List<Node>> listingAlt2 = new List<List<Node>>();
            if (nodeToCodeUIDs.Count != 0)
            {
                foreach (uint nodeID in nodeToCodeUIDs)
                {
                    if (graph.GetNode(nodeID) != null)
                    {
                        nodeToCodeInputList.Add(graph.GetNode(nodeID));
                    }
                    else
                    {
                        if (this.codeBlockUIDMap[nodeID] != null)
                        {
                            foreach (KeyValuePair<int, uint> pair in this.codeBlockUIDMap[nodeID])
                            {
                                nodeToCodeInputList.Add(graph.GetNode(pair.Value));
                            }
                        }
                    }
                }
                //listingAlternate = GetConnectedComponents(nodeToCodeInputList, graph);
                listingAlt2 = GetConnectedComponents_02(nodeToCodeInputList, graph);
            }
            #endregion

            //foreach (List<Node> n1 in listing)
            //{
            //    foreach (Node n2 in n1)
            //        if (!finalScript.Contains(n2))
            //            finalScript.Add(n2);
            //        else
            //        {
            //            finalScript.Remove(n2);
            //            finalScript.Add(n2);
            //        }
            //}
            listing = SortCodeBlocks(listing);
            List<List<Node>> finalList = new List<List<Node>>();
            foreach (List<Node> l1 in listingAlt2)
            {
                List<Node> temp = new List<Node>();
                foreach (Node n1 in l1)
                    foreach (Node listingNode in listing)
                        if (listingNode.Guid == n1.Guid)
                            temp.Add(listingNode);
                if (temp.Count != 0)
                    finalList.Add(temp);
            }            
            islandNodeList = islandNodeList.Union(islandNodes).ToList();
            //islandNodeList = SortCodeBlocks(islandNodeList);
            //if (islandNodeList.Count != 0)
            //    finalList.Add(islandNodeList);

            #region generate code and snapshot node
            uint id = 0;
            foreach (List<Node> nodeList in finalList)
            {
                string output = "";
                List<Node> tempList = SortCodeBlocks(nodeList);
                //tempList.Reverse();
                foreach (Node node in tempList)
                {
                    if (nodeToCodeUIDs.Contains(node.Guid))
                    {
                        if (node.ToCode() != null)
                            output += node.ToCode().Replace(";", "") + ProtoCore.DSASM.Constants.termline;
                    }
                    else
                    {
                        foreach (KeyValuePair<uint, Dictionary<int, uint>> pair in this.codeBlockUIDMap)
                        {
                            if (pair.Value.ContainsValue(node.Guid))
                            {
                                output += node.ToCode().Replace(";", "") + ProtoCore.DSASM.Constants.termline; //ensure only one semicolon at the end of a statement, by request from UI
                            }
                        }
                    }    
                }
                output = output.TrimEnd('\n');
                SnapshotNode ssn = new SnapshotNode();
                ssn.Id = id++;
                ssn.Content = output;
                ssn.Type = SnapshotNodeType.CodeBlock;
                ssn.InputList = new List<Connection>();

                foreach (SnapshotNode inputNode in inputs)
                {
                    foreach (Node subTreeNode in nodeList)
                    {
                        if (inputNode.Id == subTreeNode.Guid)
                        {
                            foreach (Connection c1 in inputNode.InputList)
                            {
                                if (!IsInternalConnection(c1, this))                //the connection is not internal, return it back to UI
                                {
                                    Connection newInputConnection = new Connection();
                                    newInputConnection.OtherNode = c1.OtherNode;
                                    newInputConnection.OtherIndex = c1.OtherIndex;
                                    newInputConnection.IsImplicit = c1.IsImplicit;
                                    string[] tokens = graph.GetNode(c1.OtherNode).Name.Split('=');
                                    newInputConnection.LocalName = tokens[0];
                                    ssn.InputList.Add(newInputConnection);
                                }
                            }
                        }
                        else if (codeBlockUIDMap.ContainsKey(inputNode.Id))         //inputNode was split
                        {
                            if (codeBlockUIDMap[inputNode.Id].ContainsValue(subTreeNode.Guid))
                            {
                                foreach (Connection c1 in inputNode.InputList)
                                {
                                    if (!IsInternalConnection(c1, this))
                                    {
                                        int indexSlot = 0;
                                        foreach (KeyValuePair<int, uint> pair in codeBlockUIDMap[inputNode.Id])
                                        {
                                            if (pair.Value == subTreeNode.Guid)
                                                indexSlot = pair.Key;
                                        }
                                        if (c1.OtherIndex == indexSlot)
                                        {
                                            Connection newInputConnection = new Connection();
                                            newInputConnection.OtherNode = c1.OtherNode;
                                            newInputConnection.OtherIndex = c1.OtherIndex;
                                            foreach (KeyValuePair<uint, Dictionary<int, uint>> pair in originalGC.codeBlockUIDMap)
                                            {
                                                if (pair.Value.ContainsValue(c1.OtherNode))                     //this means if the other node was split, return the original Id that was sent to us by the UI
                                                {
                                                    newInputConnection.OtherNode = pair.Key;
                                                    newInputConnection.OtherIndex = pair.Value.First(x => x.Value == c1.OtherNode).Key;
                                                }
                                            }
                                            newInputConnection.IsImplicit = c1.IsImplicit;
                                            string[] tokens = graph.GetNode(c1.OtherNode).Name.Split('=');
                                            newInputConnection.LocalName = tokens[0];
                                            ssn.InputList.Add(newInputConnection);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                ssn.OutputList = new List<Connection>();
                foreach (SnapshotNode inputNode in inputs)
                {
                    foreach (Node subTreeNode in nodeList)
                    {
                        //if (subTreeNode.Name.Split('=')[0] == outputCnt.LocalName)
                        if (inputNode.Id == subTreeNode.Guid)
                        {
                            foreach (Connection c1 in inputNode.OutputList)
                            {
                                if (!IsInternalConnection(c1, this))
                                {
                                    Connection newOutputConnection = new Connection();
                                    newOutputConnection.OtherNode = c1.OtherNode;
                                    newOutputConnection.OtherIndex = c1.OtherIndex;
                                    newOutputConnection.IsImplicit = c1.IsImplicit;
                                    newOutputConnection.LocalName = c1.LocalName;
                                    ssn.OutputList.Add(newOutputConnection);
                                }
                            }
                        }

                        else if (codeBlockUIDMap.ContainsKey(inputNode.Id))         //inputNode was split
                        {
                            if (codeBlockUIDMap[inputNode.Id].ContainsValue(subTreeNode.Guid))
                            {
                                foreach (Connection c1 in inputNode.OutputList)
                                {
                                    if (!IsInternalConnection(c1, this))
                                    {
                                        int indexSlot = 0;
                                        foreach (KeyValuePair<int, uint> pair in codeBlockUIDMap[inputNode.Id])
                                        {
                                            if (pair.Value == subTreeNode.Guid)
                                            {
                                                indexSlot = pair.Key;
                                                break;
                                            }
                                        }
                                        if (c1.LocalIndex == indexSlot)
                                        {
                                            Connection newOutputConnection = new Connection();
                                            newOutputConnection.OtherNode = c1.OtherNode;
                                            newOutputConnection.OtherIndex = c1.OtherIndex;
                                            foreach (KeyValuePair<uint, Dictionary<int, uint>> pair in originalGC.codeBlockUIDMap)
                                            {
                                                if (pair.Value.ContainsValue(c1.OtherNode))                     //this means if the other node was split, return the original Id that was sent to us by the UI
                                                {
                                                    newOutputConnection.OtherNode = pair.Key;
                                                    newOutputConnection.OtherIndex = pair.Value.First(x => x.Value == c1.OtherNode).Key;
                                                }
                                            }
                                            newOutputConnection.IsImplicit = c1.IsImplicit;
                                            newOutputConnection.LocalName = c1.LocalName;
                                            ssn.OutputList.Add(newOutputConnection);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                result.Add(ssn);
            }
            #endregion

            #region remove _temp_xxx name
            //Dictionary<string, string> tempReplaceValue = new Dictionary<string, string>();
            //for (int i = 0; i < result.Count; i++)
            //{
            //    SnapshotNode ssn = result[i];
            //    string[] statements = ssn.Content.Split(';');
            //    for (int j = 0; j < statements.Length; j++)
            //    {
            //        string statement = statements[j];
            //        string lhsTempName = statement.Split('=')[0].Replace("\n", "").Trim();
            //        foreach (Node astNode in graph.nodeList)
            //        {
            //            if (astNode.Name.Split('=')[0].Trim() == lhsTempName && lhsTempName.StartsWith("_temp_"))
            //            {
            //                //this means in the ast there is some statement _temp_abc = something
            //                //which means the _temp_xxx is generated, not typed in by users
            //                tempReplaceValue.Add(lhsTempName, statement.Split('=')[1].Replace("\n", "").Trim());
            //            }
            //        }
            //    }
            //}
            //for (int i = 0; i < result.Count; i++)
            //{
            //    SnapshotNode ssn = result[i];
            //    foreach (KeyValuePair<string, string> pair in tempReplaceValue)
            //    {
            //        ssn.Content.Replace(pair.Key, pair.Value);
            //    }
            //}
            #endregion

            #region replace _temp_ name with more elegant name
            //int tempId = 0;
            //for (int i = 0; i < result.Count; i++)
            //{
            //    SnapshotNode ssn = result[i];
            //    string[] statements = ssn.Content.Split(';');
            //    for (int j = 0; j < statements.Length; j++)
            //    {
            //        string statement = statements[j];
            //        string lhsTempName = statement.Split('=')[0].Replace("\n", "").Trim();
            //        foreach (Node astNode in graph.nodeList)
            //        {
            //            if (astNode.Name.Split('=')[0].Trim() == lhsTempName && lhsTempName.StartsWith("_temp_"))
            //            {
            //                string newTempName = "temp_" + tempId++;
            //                for (int k = 0; k < result.Count; k++)
            //                {
            //                    result[k].Content = result[k].Content.Replace(lhsTempName, newTempName);
            //                }
            //            }
            //        }
            //        if (statement.Split('=').Length > 1)
            //        {
            //            string rhsTempName = statement.Split('=')[1].Replace("\n", "").Trim();
            //            foreach (Node astNode in graph.nodeList)
            //            {
            //                if (astNode.Name.Split('=')[0].Trim() == rhsTempName && rhsTempName.StartsWith("_temp_"))
            //                {
            //                    string newTempName = "temp_" + tempId++;
            //                    for (int k = 0; k < result.Count; k++)
            //                    {
            //                        result[k].Content = result[k].Content.Replace(rhsTempName, newTempName);
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}
            #endregion

            #region return to original input connections
            for (int i = 0; i < result.Count; i++)
            {
                SnapshotNode ssn = result[i];
                for (int j = 0; j < ssn.InputList.Count; j++)
                {
                    Connection inputConnection = ssn.InputList[j];
                    foreach (KeyValuePair<uint, Dictionary<int, uint>> kvp in originalGC.codeBlockUIDMap)
                    {
                        foreach (KeyValuePair<int, uint> kvp2 in kvp.Value)
                        {
                            if (kvp2.Value == inputConnection.OtherNode)
                            {
                                Connection oldInputConnection = new Connection();
                                oldInputConnection.OtherNode = kvp.Key;
                                oldInputConnection.OtherIndex = inputConnection.OtherIndex;
                                oldInputConnection.IsImplicit = inputConnection.IsImplicit;
                                oldInputConnection.LocalName = inputConnection.LocalName;
                                oldInputConnection.LocalIndex = inputConnection.LocalIndex;
                                ssn.InputList.Remove(inputConnection);
                                ssn.InputList.Insert(j, oldInputConnection);
                            }
                        }
                    }
                }

                for (int j = 0; j < ssn.OutputList.Count; j++)
                {
                    Connection outputConnection = ssn.OutputList[j];
                    foreach (KeyValuePair<uint, Dictionary<int, uint>> kvp in originalGC.codeBlockUIDMap)
                    {
                        foreach (KeyValuePair<int, uint> kvp2 in kvp.Value)
                        {
                            if (kvp2.Value == outputConnection.OtherNode)
                            {
                                Connection oldInputConnection = new Connection();
                                oldInputConnection.OtherNode = kvp.Key;
                                oldInputConnection.OtherIndex = outputConnection.OtherIndex;
                                oldInputConnection.IsImplicit = outputConnection.IsImplicit;
                                oldInputConnection.LocalName = outputConnection.LocalName;
                                oldInputConnection.LocalIndex = outputConnection.LocalIndex;
                                ssn.OutputList.Remove(outputConnection);
                                ssn.OutputList.Insert(j, oldInputConnection);
                            }
                        }
                    }
                }
            }
            #endregion
            /*Chirag's
            foreach (var value in finalScript)
            {
                if (nodeToCodeUIDs.Contains((value as Node).Guid))
                    if (value.ToCode() != null)
                        liststat += value.ToCode() + ProtoCore.DSASM.Constants.termline;
            }
            liststat = builder.ToString() + liststat;
            //liststat += builder.ToString();
            //GraphUtilities.runningUID = GraphToDSCompiler.Constants.UIDStart;
            //result.AddRange(liststat.Split(';'));
            */
            UpdateAddedNodesInModifiedNameList();

            return result;
        }
예제 #14
0
        private List<SnapshotNode> CreateSnapshotNodesFromVisualNodes(List<IVisualNode> nodeList)
        {
            if (nodeList == null)
                throw new ArgumentNullException("nodeList");

            List<SnapshotNode> ssnList = new List<SnapshotNode>();
            foreach (VisualNode node in nodeList)
            {
                if (false != node.Error) // Ignore erroneous node.
                    continue;

                SnapshotNodeType type = SnapshotNodeType.None;
                string content = node.ToCode(out type);
                SnapshotNode ssn = new SnapshotNode(node.NodeId, type, content);
                node.GetAssignmentStatements(ssn.Assignments);
                ssn.InputList = new List<Connection>();
                ssn.OutputList = new List<Connection>();

                List<uint> localSlotIdList = new List<uint>();
                if (node.GetInputSlots() != null)
                    localSlotIdList.AddRange(node.GetInputSlots());
                if (node.GetOutputSlots() != null)
                    localSlotIdList.AddRange(node.GetOutputSlots());

                foreach (uint localSlotId in localSlotIdList)
                {
                    ISlot localSlot = this.GetSlot(localSlotId);
                    if (localSlot.ConnectingSlots != null)
                    {
                        foreach (uint otherSlotId in localSlot.ConnectingSlots)
                        {
                            ISlot otherSlot = this.GetSlot(otherSlotId);
                            uint otherNodeId = otherSlot.Owners[0];
                            VisualNode otherNode = this.GetVisualNode(otherNodeId);
                            if (false != otherNode.Error) // Ignore erroneous node.
                                continue;
                            uint edgeId;
                            if (localSlot.SlotType == SlotType.Input)
                                edgeId = edgeController.GetEdgeId(otherSlotId, localSlotId);
                            else
                                edgeId = edgeController.GetEdgeId(localSlotId, otherSlotId);
                            bool isImplicitConnection = edgeController.isImplicitEdge(edgeId);

                            ssn.ConnectTo(
                                otherNodeId,                            // Connect to UID
                                node.GetSlotIndex(localSlotId),         // Local slot index of this node
                                otherNode.GetSlotIndex(otherSlotId),    // Destination node slot index
                                SlotType.Input == localSlot.SlotType,   // Is this node an input
                                isImplicitConnection,                   //is edge implicit
                                ((Slot)localSlot).GetSlotName());       // The name of the local slot
                        }
                    }
                }

                ssnList.Add(ssn);
            }
            return ssnList;
        }
예제 #15
0
        /// <summary>
        /// Given a graph, rewrite is given the heuristics of this pattern class
        /// </summary>
        /// <param name="graph"></param>
        /// <returns></returns>
        public List <SnapshotNode> RewriteFromPattern(List <SnapshotNode> graph)
        {
            List <SnapshotNode> n = new List <SnapshotNode>();

            foreach (SnapshotNode c in graph)
            {
                n.Add(c);
            }
            foreach (SnapshotNode node in n)
            {
                if (node.Type == SnapshotNodeType.Function)
                {
                    string[] functionQualifers = node.Content.Split(';');
                    switch (functionQualifers[1])
                    {
                    case "PlaneBy3Points":
                        SnapshotNode funcWrap = new SnapshotNode((uint)node.Id * 101, SnapshotNodeType.CodeBlock, "def PlaneBy3Points(p1, p2, p3) \n{\n    temp1 = p3.X - p1.X;\n    temp2 = p3.Y - p1.Y;\n    temp3 = p3.Z - p1.Z;\n    temp4 = p2.X - p1.X;\n    temp5 = p2.Y - p1.Y;\n    temp6 = p2.Z - p1.Z;\n    temp7 = Vector.ByCoordinates(temp1, temp2, temp3);\n    temp8 = Vector.ByCoordinates(temp4, temp5, temp6);\n    return = Plane.ByOriginNormal(p1,temp8.Cross(temp7));\n}");
                        graph.Add(funcWrap);

                        /*List<Connection> inp = new List<Connection>();
                         * foreach (Connection c in node.InputList)
                         *  inp.Add(c);
                         * SnapshotNode ssn = new SnapshotNode((uint)(node.Id), node.Type, ";PlaneBy3Points; ");
                         * ssn.InputList = inp;
                         * ssn.OutputList = new List<Connection>();
                         * int num = graph.IndexOf(node);
                         * graph[num] = ssn;*/
                        //node.Content=";PlaneBy3Points;";

                        /*
                         * List<uint> pointsl=new List<uint>();
                         * foreach(Connection c in node.InputList)
                         *  pointsl.Add(c.OtherNode);
                         * SnapshotNode p1 = n.Find(x => x.Id == pointsl[0]);
                         * List<uint> p1cords = new List<uint>();
                         * foreach (Connection c in p1.InputList)
                         *  p1cords.Add(c.OtherNode);
                         * SnapshotNode p1x = n.Find(x => x.Id == p1cords[0]);
                         * SnapshotNode p1y = n.Find(x => x.Id == p1cords[1]);
                         * SnapshotNode p1z = n.Find(x => x.Id == p1cords[2]);
                         * SnapshotNode p2 = n.Find(x => x.Id == pointsl[1]);
                         * List<uint> p2cords = new List<uint>();
                         * foreach (Connection c in p2.InputList)
                         *  p2cords.Add(c.OtherNode);
                         * SnapshotNode p2x = n.Find(x => x.Id == p1cords[0]);
                         * SnapshotNode p2y = n.Find(x => x.Id == p1cords[1]);
                         * SnapshotNode p2z = n.Find(x => x.Id == p1cords[2]);
                         * SnapshotNode p3 = n.Find(x => x.Id == pointsl[2]);
                         * List<uint> p3cords = new List<uint>();
                         * foreach (Connection c in p3.InputList)
                         *  p3cords.Add(c.OtherNode);
                         * SnapshotNode p3x = n.Find(x => x.Id == p1cords[0]);
                         * SnapshotNode p3y = n.Find(x => x.Id == p1cords[1]);
                         * SnapshotNode p3z = n.Find(x => x.Id == p1cords[2]);
                         * SnapshotNode vector1x = new SnapshotNode((uint)((Math.Pow(p3x.Id,p1x.Id)) * 10), node.Type, ";-; ");
                         * vector1x.OutputList = new List<Connection>();
                         * vector1x.InputList = new List<Connection>();
                         * Connection vector1x1 = new Connection();
                         * vector1x1.LocalIndex = 0;
                         * vector1x1.OtherIndex = 0;
                         * vector1x1.OtherNode = p3x.Id;
                         * Connection vector1x2 = new Connection();
                         * vector1x2.LocalIndex = 1;
                         * vector1x2.OtherIndex = 0;
                         * vector1x2.OtherNode = p1x.Id;
                         * vector1x.InputList.Add(vector1x1);
                         * vector1x.InputList.Add(vector1x2);
                         * graph.Add(vector1x);
                         * SnapshotNode vector1y = new SnapshotNode((uint)((Math.Pow(p3y.Id, p1y.Id)) * 10), node.Type, ";-; ");
                         * vector1y.OutputList = new List<Connection>();
                         * vector1y.InputList = new List<Connection>();
                         * Connection vector1y1 = new Connection();
                         * vector1y1.LocalIndex = 0;
                         * vector1y1.OtherIndex = 0;
                         * vector1y1.OtherNode = p3y.Id;
                         * Connection vector1y2 = new Connection();
                         * vector1y2.LocalIndex = 1;
                         * vector1y2.OtherIndex = 0;
                         * vector1y2.OtherNode = p1y.Id;
                         * vector1y.InputList.Add(vector1y1);
                         * vector1y.InputList.Add(vector1y2);
                         * graph.Add(vector1y);
                         * SnapshotNode vector1z = new SnapshotNode((uint)((Math.Pow(p3z.Id, p1z.Id)) * 10), node.Type, ";-; ");
                         * vector1z.OutputList = new List<Connection>();
                         * vector1z.InputList = new List<Connection>();
                         * Connection vector1z1 = new Connection();
                         * vector1z1.LocalIndex = 0;
                         * vector1z1.OtherIndex = 0;
                         * vector1z1.OtherNode = p3z.Id;
                         * Connection vector1z2 = new Connection();
                         * vector1z2.LocalIndex = 1;
                         * vector1z2.OtherIndex = 0;
                         * vector1z2.OtherNode = p1z.Id;
                         * vector1z.InputList.Add(vector1z1);
                         * vector1z.InputList.Add(vector1z2);
                         * graph.Add(vector1z);
                         * SnapshotNode vector2x = new SnapshotNode((uint)((Math.Pow(p2x.Id,p1x.Id)) * 10), node.Type, ";-; ");
                         * vector2x.OutputList = new List<Connection>();
                         * vector2x.InputList = new List<Connection>();
                         * Connection vector2x1 = new Connection();
                         * vector2x1.LocalIndex = 0;
                         * vector2x1.OtherIndex = 0;
                         * vector2x1.OtherNode = p2x.Id;
                         * Connection vector2x2 = new Connection();
                         * vector2x2.LocalIndex = 1;
                         * vector2x2.OtherIndex = 0;
                         * vector2x2.OtherNode = p1x.Id;
                         * vector2x.InputList.Add(vector2x1);
                         * vector2x.InputList.Add(vector2x2);
                         * graph.Add(vector2x);
                         * SnapshotNode vector2y = new SnapshotNode((uint)((Math.Pow(p2y.Id, p1y.Id)) * 10), node.Type, ";-; ");
                         * vector2y.OutputList = new List<Connection>();
                         * vector2y.InputList = new List<Connection>();
                         * Connection vector2y1 = new Connection();
                         * vector2y1.LocalIndex = 0;
                         * vector2y1.OtherIndex = 0;
                         * vector2y1.OtherNode = p2y.Id;
                         * Connection vector2y2 = new Connection();
                         * vector2y2.LocalIndex = 1;
                         * vector2y2.OtherIndex = 0;
                         * vector2y2.OtherNode = p1y.Id;
                         * vector2y.InputList.Add(vector2y1);
                         * vector2y.InputList.Add(vector2y2);
                         * graph.Add(vector2y);
                         * SnapshotNode vector2z = new SnapshotNode((uint)((Math.Pow(p2z.Id, p1z.Id)) * 10), node.Type, ";-; ");
                         * vector2z.OutputList = new List<Connection>();
                         * vector2z.InputList = new List<Connection>();
                         * Connection vector2z1 = new Connection();
                         * vector2z1.LocalIndex = 0;
                         * vector2z1.OtherIndex = 0;
                         * vector2z1.OtherNode = p2z.Id;
                         * Connection vector2z2 = new Connection();
                         * vector2z2.LocalIndex = 1;
                         * vector2z2.OtherIndex = 0;
                         * vector2z2.OtherNode = p1z.Id;
                         * vector2z.InputList.Add(vector2z1);
                         * vector2z.InputList.Add(vector2z2);
                         * graph.Add(vector2z);*/
                        ;
                        break;

                    default: break;
                    }
                }
            }
            return(graph);
        }
예제 #16
0
 public SnapshotNode JoinNode(SnapshotNode nodeA, SnapshotNode nodeB)
 {
     SnapshotNode newNode = new SnapshotNode();
     newNode.Id = Math.Min(nodeA.Id, nodeB.Id);
     newNode.Type = SnapshotNodeType.CodeBlock;
     newNode.Content = nodeA.Content + nodeB.Content;
     newNode.InputList = nodeA.InputList.Union<Connection>(nodeB.InputList).ToList();
     newNode.OutputList = nodeA.OutputList.Union<Connection>(nodeB.OutputList).ToList();
     return newNode;
 }
예제 #17
0
        private SynchronizeData CreateSynchronizeDataForGuidList(Dictionary<uint, string> modfiedGuidList)
        {
            Dictionary<uint, SnapshotNode> modifiedGuids = new Dictionary<uint, SnapshotNode>();
            SynchronizeData syncDataReturn = new SynchronizeData();

            if (modfiedGuidList != null)
            {
                //foreach (uint guid in modfiedGuidList)
                foreach (var kvp in modfiedGuidList)
                {
                    // Get the uid recognized by the graphIDE
                    uint guid = kvp.Key;
                    string name = kvp.Value;
                    SnapshotNode sNode = new SnapshotNode(this.graphCompiler.GetRealUID(guid), SnapshotNodeType.Identifier, name);
                    if (!modifiedGuids.ContainsKey(sNode.Id))
                    {
                        modifiedGuids.Add(sNode.Id, sNode);
                    }
                }

                foreach (KeyValuePair<uint, SnapshotNode> kvp in modifiedGuids)
                    syncDataReturn.ModifiedNodes.Add(kvp.Value);
            }

            return syncDataReturn;
        }
예제 #18
0
 /// <summary>
 /// Given a graph, rewrite is given the heuristics of this pattern class
 /// </summary>
 /// <param name="graph"></param>
 /// <returns></returns>
 public List<SnapshotNode> RewriteFromPattern(List<SnapshotNode> graph)
 {
     List<SnapshotNode> n = new List<SnapshotNode>();
     foreach (SnapshotNode c in graph)
         n.Add(c);
     foreach (SnapshotNode node in n)
     {
         if (node.Type == SnapshotNodeType.Function)
         {
             string[] functionQualifers = node.Content.Split(';');
             switch (functionQualifers[1])
             {
                 case "PlaneBy3Points":
                     SnapshotNode funcWrap = new SnapshotNode((uint)node.Id * 101, SnapshotNodeType.CodeBlock, "def PlaneBy3Points(p1, p2, p3) \n{\n    temp1 = p3.X - p1.X;\n    temp2 = p3.Y - p1.Y;\n    temp3 = p3.Z - p1.Z;\n    temp4 = p2.X - p1.X;\n    temp5 = p2.Y - p1.Y;\n    temp6 = p2.Z - p1.Z;\n    temp7 = Vector.ByCoordinates(temp1, temp2, temp3);\n    temp8 = Vector.ByCoordinates(temp4, temp5, temp6);\n    return = Plane.ByOriginNormal(p1,temp8.Cross(temp7));\n}");
                     graph.Add(funcWrap);
                     /*List<Connection> inp = new List<Connection>();
                     foreach (Connection c in node.InputList)
                         inp.Add(c);
                     SnapshotNode ssn = new SnapshotNode((uint)(node.Id), node.Type, ";PlaneBy3Points; ");
                     ssn.InputList = inp;
                     ssn.OutputList = new List<Connection>();
                     int num = graph.IndexOf(node);
                     graph[num] = ssn;*/
                     //node.Content=";PlaneBy3Points;";
                     /*
                     List<uint> pointsl=new List<uint>();
                     foreach(Connection c in node.InputList)
                         pointsl.Add(c.OtherNode);
                     SnapshotNode p1 = n.Find(x => x.Id == pointsl[0]);
                     List<uint> p1cords = new List<uint>();
                     foreach (Connection c in p1.InputList)
                         p1cords.Add(c.OtherNode);
                     SnapshotNode p1x = n.Find(x => x.Id == p1cords[0]);
                     SnapshotNode p1y = n.Find(x => x.Id == p1cords[1]);
                     SnapshotNode p1z = n.Find(x => x.Id == p1cords[2]);
                     SnapshotNode p2 = n.Find(x => x.Id == pointsl[1]);
                     List<uint> p2cords = new List<uint>();
                     foreach (Connection c in p2.InputList)
                         p2cords.Add(c.OtherNode);
                     SnapshotNode p2x = n.Find(x => x.Id == p1cords[0]);
                     SnapshotNode p2y = n.Find(x => x.Id == p1cords[1]);
                     SnapshotNode p2z = n.Find(x => x.Id == p1cords[2]);
                     SnapshotNode p3 = n.Find(x => x.Id == pointsl[2]);
                     List<uint> p3cords = new List<uint>();
                     foreach (Connection c in p3.InputList)
                         p3cords.Add(c.OtherNode);
                     SnapshotNode p3x = n.Find(x => x.Id == p1cords[0]);
                     SnapshotNode p3y = n.Find(x => x.Id == p1cords[1]);
                     SnapshotNode p3z = n.Find(x => x.Id == p1cords[2]);
                     SnapshotNode vector1x = new SnapshotNode((uint)((Math.Pow(p3x.Id,p1x.Id)) * 10), node.Type, ";-; ");
                     vector1x.OutputList = new List<Connection>();
                     vector1x.InputList = new List<Connection>();
                     Connection vector1x1 = new Connection();
                     vector1x1.LocalIndex = 0;
                     vector1x1.OtherIndex = 0;
                     vector1x1.OtherNode = p3x.Id;
                     Connection vector1x2 = new Connection();
                     vector1x2.LocalIndex = 1;
                     vector1x2.OtherIndex = 0;
                     vector1x2.OtherNode = p1x.Id;
                     vector1x.InputList.Add(vector1x1);
                     vector1x.InputList.Add(vector1x2);
                     graph.Add(vector1x);
                     SnapshotNode vector1y = new SnapshotNode((uint)((Math.Pow(p3y.Id, p1y.Id)) * 10), node.Type, ";-; ");
                     vector1y.OutputList = new List<Connection>();
                     vector1y.InputList = new List<Connection>();
                     Connection vector1y1 = new Connection();
                     vector1y1.LocalIndex = 0;
                     vector1y1.OtherIndex = 0;
                     vector1y1.OtherNode = p3y.Id;
                     Connection vector1y2 = new Connection();
                     vector1y2.LocalIndex = 1;
                     vector1y2.OtherIndex = 0;
                     vector1y2.OtherNode = p1y.Id;
                     vector1y.InputList.Add(vector1y1);
                     vector1y.InputList.Add(vector1y2);
                     graph.Add(vector1y);
                     SnapshotNode vector1z = new SnapshotNode((uint)((Math.Pow(p3z.Id, p1z.Id)) * 10), node.Type, ";-; ");
                     vector1z.OutputList = new List<Connection>();
                     vector1z.InputList = new List<Connection>();
                     Connection vector1z1 = new Connection();
                     vector1z1.LocalIndex = 0;
                     vector1z1.OtherIndex = 0;
                     vector1z1.OtherNode = p3z.Id;
                     Connection vector1z2 = new Connection();
                     vector1z2.LocalIndex = 1;
                     vector1z2.OtherIndex = 0;
                     vector1z2.OtherNode = p1z.Id;
                     vector1z.InputList.Add(vector1z1);
                     vector1z.InputList.Add(vector1z2);
                     graph.Add(vector1z);
                     SnapshotNode vector2x = new SnapshotNode((uint)((Math.Pow(p2x.Id,p1x.Id)) * 10), node.Type, ";-; ");
                     vector2x.OutputList = new List<Connection>();
                     vector2x.InputList = new List<Connection>();
                     Connection vector2x1 = new Connection();
                     vector2x1.LocalIndex = 0;
                     vector2x1.OtherIndex = 0;
                     vector2x1.OtherNode = p2x.Id;
                     Connection vector2x2 = new Connection();
                     vector2x2.LocalIndex = 1;
                     vector2x2.OtherIndex = 0;
                     vector2x2.OtherNode = p1x.Id;
                     vector2x.InputList.Add(vector2x1);
                     vector2x.InputList.Add(vector2x2);
                     graph.Add(vector2x);
                     SnapshotNode vector2y = new SnapshotNode((uint)((Math.Pow(p2y.Id, p1y.Id)) * 10), node.Type, ";-; ");
                     vector2y.OutputList = new List<Connection>();
                     vector2y.InputList = new List<Connection>();
                     Connection vector2y1 = new Connection();
                     vector2y1.LocalIndex = 0;
                     vector2y1.OtherIndex = 0;
                     vector2y1.OtherNode = p2y.Id;
                     Connection vector2y2 = new Connection();
                     vector2y2.LocalIndex = 1;
                     vector2y2.OtherIndex = 0;
                     vector2y2.OtherNode = p1y.Id;
                     vector2y.InputList.Add(vector2y1);
                     vector2y.InputList.Add(vector2y2);
                     graph.Add(vector2y);
                     SnapshotNode vector2z = new SnapshotNode((uint)((Math.Pow(p2z.Id, p1z.Id)) * 10), node.Type, ";-; ");
                     vector2z.OutputList = new List<Connection>();
                     vector2z.InputList = new List<Connection>();
                     Connection vector2z1 = new Connection();
                     vector2z1.LocalIndex = 0;
                     vector2z1.OtherIndex = 0;
                     vector2z1.OtherNode = p2z.Id;
                     Connection vector2z2 = new Connection();
                     vector2z2.LocalIndex = 1;
                     vector2z2.OtherIndex = 0;
                     vector2z2.OtherNode = p1z.Id;
                     vector2z.InputList.Add(vector2z1);
                     vector2z.InputList.Add(vector2z2);
                     graph.Add(vector2z);*/
                     ;
                     break;
                 default: break;
             }
         }
     }
     return graph;
 }
예제 #19
0
 /// <summary>
 /// Given a graph, rewrite is given the heuristics of this pattern class
 /// </summary>
 /// <param name="graph"></param>
 /// <returns></returns>
 public List<SnapshotNode> RewriteFromPattern(List<SnapshotNode> graph)
 {
     List<SnapshotNode> n = new List<SnapshotNode>();
     foreach (SnapshotNode c in graph)
         n.Add(c);
     foreach (SnapshotNode node in n)
     {
         if (node.Type == SnapshotNodeType.Function)
         {
             string[] functionQualifers = node.Content.Split(';');
             switch (functionQualifers[1])
             {
                 case "CircleBy3Points":
                     SnapshotNode funcWrap = new SnapshotNode((uint)node.Id * 101, SnapshotNodeType.CodeBlock, "def CircleBy3Points(p1, p2, p3) \n{\n    temp1 = p3.X - p1.X;\n    temp2 = p3.Y - p1.Y;\n    temp3 = p3.Z - p1.Z;\n    temp4 = p2.X - p1.X;\n    temp5 = p2.Y - p1.Y;\n    temp6 = p2.Z - p1.Z;\n    temp7 = Vector.ByCoordinates(temp1, temp2, temp3);\n    temp8 = Vector.ByCoordinates(temp4, temp5, temp6);\n    centerX = (p1.X + p2.X + p3.X) / 3;\n    centerY = (p1.Y + p2.Y + p3.Y) / 3;\n    centerZ = (p1.Z + p2.Z + p3.Z) / 3;\n    centre = Point.ByCoordinates(centerX, centerY, centerZ);\n    radius = centre.DistanceTo(p1);return = Circle.ByCenterPointRadius(centre, radius,temp8.Cross(temp7));\n}");
                     graph.Add(funcWrap);
                     break;
                 default: break;
             }
         }
     }
     return graph;
 }
예제 #20
0
        public bool UpdateNodes(SnapshotNode node)
        {
            uint guidToUpdate = node.Id;
            string content = node.Content;

            Node nodeToUpdate = graph.GetNode(guidToUpdate);
            nodeToUpdate.Name = content;

            // TODO Jun: Check with Luke/Chirag what the codeblock node can contain
            if (node.Type == SnapshotNodeType.CodeBlock || node.Type == SnapshotNodeType.Literal)
            {
                (nodeToUpdate as Block).content = content;
            }

            return true;
        }
예제 #21
0
        public void TestConstructorFromSnapshotNode()
        {
            IGraphController graphController = new GraphController(null);
            uint id = 0x10000001;
            string content = "a = b;\nc = d;";
            GraphToDSCompiler.SnapshotNode snapshotNode = new GraphToDSCompiler.SnapshotNode(id, GraphToDSCompiler.SnapshotNodeType.CodeBlock, content);
            CodeBlockNode node = new CodeBlockNode(graphController, snapshotNode);

            Assert.IsNotNull(node);
            Assert.AreEqual(id, node.NodeId);
            Assert.AreEqual(content, node.Text);

            uint[] outputSlots = node.GetOutputSlots();
            uint[] inputSlots = node.GetInputSlots();
            Assert.AreEqual(2, outputSlots.Length);
            Assert.AreEqual(2, inputSlots.Length);
        }