Example #1
0
        public override Node visitPrimitiveTypes(JuliarParser.PrimitiveTypesContext ctx)
        {
            PrimitiveNode node = new PrimitiveNode();

            new IterateOverContext(this, ctx, this, node);
            return(node);
        }
Example #2
0
        private int aggregateVariable(IList <VariableNode> variableNodeList, ActivationFrame frame)
        {
            int sum = 0;

            for (int i = 0; i < variableNodeList.Count; i++)
            {
                Node      v         = frame.variableSet[variableNodeList[i].variableName];
                FinalNode finalNode = null;

                if (v is FinalNode && v.Instructions.Count == 0)
                {
                    finalNode = (FinalNode)v;
                }

                if (v is PrimitiveNode)
                {
                    PrimitiveNode primitiveNode = (PrimitiveNode)v;
                    finalNode = (FinalNode)primitiveNode.Instructions[0];
                }

                if (finalNode != null)
                {
                    sum += Convert.ToInt32(finalNode.dataString());
                }
            }

            return(sum);
        }
Example #3
0
        private string getFileName(List <PrimitiveNode> pNodes, int nodeOffset)
        {
            PrimitiveNode tlNode = (from pnode in pNodes
                                    where pnode.Nodestring.Equals("Texture library")
                                    select pnode).FirstOrDefault();

            if (tlNode == null)
            {
                throw new Exception("Couldn't find Texture Library node");
            }

            PrimitiveNode tlSubNode = (from pnode in pNodes
                                       where pnode.InitialPos == nodeOffset + tlNode.ChildOffset
                                       select pnode).FirstOrDefault();

            if (tlNode == null)
            {
                throw new Exception("Couldn't find Texture Library sub node");
            }

            if (tlSubNode.PeerNextOffset == 0)
            {
                string fileName = "";
                if (tlSubNode.Nodestring.EndsWith(".tga"))
                {
                    fileName = tlSubNode.Nodestring.Remove(tlSubNode.Nodestring.LastIndexOf(".tga"), 4);
                }

                return(fileName);
            }
            else
            {
                throw new Exception("Multiple texture library sub nodes");
            }
        }
Example #4
0
        public override Node visitPrimitives(JuliarParser.PrimitivesContext ctx)
        {
            PrimitiveNode      primitiveNode = new PrimitiveNode();
            IterateOverContext context       = new IterateOverContext(this);

            context.iterateOverChildren(ctx, this, primitiveNode);
            return(primitiveNode);
        }
Example #5
0
        public static void TestEqualityWithDifferentNodeTypes()
        {
            var groupNode     = new GroupNode("group", Repetition.Required, new Node[0]);
            var primitiveNode = new PrimitiveNode("primitive", Repetition.Required, PhysicalType.Int32);

            Assert.AreNotEqual(groupNode, primitiveNode);
            Assert.AreNotEqual(primitiveNode, groupNode);
        }
Example #6
0
        public static void TestNodeUtf8Name()
        {
            const string name = "2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm";

            using var groupNode     = new GroupNode(name, Repetition.Required, new Node[0]);
            using var primitiveNode = new PrimitiveNode(name, Repetition.Required, LogicalType.Int(32, true), PhysicalType.Int32);

            Assert.AreEqual(name, groupNode.Name);
            Assert.AreEqual(name, primitiveNode.Name);
        }
Example #7
0
    public override Node Create(Vector2 pos)
    {     // This function has to be registered in Node_Editor.ContextCallback
        PrimitiveNode node = CreateInstance <PrimitiveNode> ();

        node.name = "Primitive Node";
        node.rect = new Rect(pos.x, pos.y, 200, 100);

        NodeInput.Create(node, "Parent", "GameObject");
        NodeOutput.Create(node, "GameObject", "GameObject");

        return(node);
    }
Example #8
0
        private string Getstring(BinaryReader br, PrimitiveNode node, int stringOffset)
        {
            string currstring = "";

            this.reader.BaseStream.Position = stringOffset + node.StringOffset;

            int currChar = 0;

            while ((currChar = this.reader.ReadByte()) != 0)
            {
                currstring += Convert.ToChar(currChar);
            }
            return(currstring);
        }
        protected override PropertyEditor AutoCreateMemberEditor(MemberInfo info)
        {
            if (ReflectionHelper.MemberInfoEquals(info, typeof(PrimitiveNode).GetProperty("PrimitiveValue")))
            {
                PrimitiveNode primitiveNode = this.GetValue().NotNull().FirstOrDefault() as PrimitiveNode;
                Type          actualType    = primitiveNode.NodeType.ToActualType();
                if (actualType == null)
                {
                    actualType = (info as PropertyInfo).PropertyType;
                }

                this.editorPrimitiveValue = this.ParentGrid.CreateEditor(actualType, this);
                return(this.editorPrimitiveValue);
            }
            else
            {
                return(base.AutoCreateMemberEditor(info));
            }
        }
Example #10
0
        public override NodeViewModel CreateModel()
        {
            PrimitiveNode result = null;

            switch (primative)
            {
            case NoisePrimitive.Constant:
                result = new ConstantNode();
                break;

            case NoisePrimitive.Spheres:
                result = new SpheresNode();
                break;

            case NoisePrimitive.Cylinders:
                result = new CylindersNode();
                break;

            case NoisePrimitive.BevinsValue:
                result = new BevinsValueNode();
                break;

            case NoisePrimitive.BevinsGradient:
                result = new BevinsGradientNode();
                break;

            case NoisePrimitive.ImprovedPerlin:
                result = new ImprovedPerlinNode();
                break;

            case NoisePrimitive.SimplexPerlin:
                result = new SimplexPerlinNode();
                break;
            }
            (result.Quality.Editor as EnumEditorViewModel).Value      = quality;
            (result.Seed.Editor as ValueEditorViewModel <int?>).Value = seed;
            (result.Offset.Editor as FloatEditorViewModel).Value      = offset;

            result.Name     = name;
            result.Position = pos;

            return(result);
        }
Example #11
0
        public static void primitiveInstance(PrimitiveNode primitiveNode, ActivationFrame activationFrame, VariableDeclarationNode variableToAssignTo)
        {
            if (canPrimitiveValueBeAssignedToVar(variableToAssignTo, primitiveNode))
            {
                string variableName;

                if (variableToAssignTo.IntegralType == juserDefined)
                {
                    variableName = variableToAssignTo.UserDefinedNode.FullyQualifiedVariableName;
                }
                else
                {
                    FinalNode variableNameTerminalNode = (FinalNode)variableToAssignTo.Instructions[1].Instructions[0];
                    variableName = variableNameTerminalNode.dataString();
                }

                if (activationFrame.variableSet.ContainsKey(variableName))
                {
                    activationFrame.variableSet.Remove(variableName);
                }

                activationFrame.variableSet[variableName] = primitiveNode;
            }
        }
Example #12
0
 public PrimitiveTreeNode(PrimitiveNode data) : base(data)
 {
     this.primitiveData = data;
 }
Example #13
0
        public string GetImage(string destPath, string nickName)
        {
            try
            {
                char[] buffer = new char[4];
                this.reader.Read(buffer, 0, 4);
                string ash = new string(buffer);

                int ver = this.reader.ReadInt32();

                if (!ash.Equals("UTF ") && ver == 257)
                {
                    throw new Exception("Wrong file format");
                }

                int nodeOffset = this.reader.ReadInt32();
                int nodeSize   = this.reader.ReadInt32();

                this.reader.BaseStream.Position = this.reader.BaseStream.Position + 8;

                int stringOffset = this.reader.ReadInt32();
                int stringSize   = this.reader.ReadInt32();

                this.reader.BaseStream.Position = this.reader.BaseStream.Position + 4;

                this.reader.BaseStream.Position = 36;
                int dataOffset = this.reader.ReadInt32();
                int dateSize   = (int)(this.reader.BaseStream.Length - this.reader.BaseStream.Position);

                #region get nodes
                this.reader.BaseStream.Position = nodeOffset;

                List <PrimitiveNode> nodes = new List <PrimitiveNode>();
                while (this.reader.BaseStream.Position < nodeOffset + nodeSize)
                {
                    nodes.Add(this.GetNode(this.reader));
                }
                #endregion

                #region get strings
                foreach (PrimitiveNode node in nodes)
                {
                    node.Nodestring = this.Getstring(this.reader, node, stringOffset);
                    //  node.PrintNode();
                }
                #endregion

                PrimitiveNode mipNode = (from node in nodes
                                         where node.Nodestring.Equals("MIP0")
                                         select node).FirstOrDefault();

                if (mipNode == null)
                {
                    throw new Exception("Couldn't locate mip node");
                }

                this.reader.BaseStream.Position = dataOffset + mipNode.ChildOffset;

                byte[] fileBytes = new byte[mipNode.Size];
                this.reader.Read(fileBytes, 0, fileBytes.Length);

                string fileName = this.getFileName(nodes, nodeOffset);
                if (fileName == "")
                {
                    fileName = nickName;
                }
                fileName += ".jpg";

                Bitmap image = TargaImage.LoadTargaImage(fileBytes);
                image.Save(destPath + fileName);

                return(fileName);

                #region test

                /*
                 * string path = @"C:\Users\Yaoquizque\Desktop\FreelancerTrading\FilesFeed\commoditiesModels\TGA\";
                 * using (BinaryWriter bw = new BinaryWriter(File.Open(path + this.getFileName(nodes, nodeOffset), FileMode.Create)))
                 * {
                 *  bw.Write(fileBytes);
                 * }*/
                #endregion
            }
            finally
            {
                this.Dispose();
            }
        }
Example #14
0
 public int CompareTo(PrimitiveNode <T> other)
 {
     return(Value.CompareTo(other.Value));
 }
Example #15
0
 public bool Equals(PrimitiveNode <T> other)
 {
     return(Equals(Value, other.Value));
 }
Example #16
0
        public static bool canPrimitiveValueBeAssignedToVar(VariableDeclarationNode lvalue, PrimitiveNode rvalue)
        {
            FinalNode rvalueTerminal = (FinalNode)rvalue.Instructions[0];

            VariableNode variableNode;

            if (juserDefined == lvalue.IntegralType)
            {
                variableNode = lvalue.UserDefinedNode.VariableNode;
            }
            else
            {
                variableNode = (VariableNode)lvalue.Instructions[1];
            }
            string data = rvalueTerminal.dataString();

            try
            {
                switch (variableNode.IntegralType)
                {
                case jinteger:
                    return(true);

                case jdouble:
                    return(true);

                case jfloat:
                    return(true);

                case jlong:
                    return(true);

                case jstring:
                    return(true);

                case jobject:
                    return(false);

                case jboolean:
                    return(Convert.ToBoolean(data));

                case juserDefined:
                    return(true);

                default:
                    return(false);
                }
            }
            catch (NumberFormatException)
            {
                return(false);
            }
        }
        public static IList <Node> evalFunctionCall(Node node, ActivationFrameStack activationFrame, string mainFunctionName, IDictionary <string, Node> functionNodeMap, Interpreter callback)
        {
            FunctionCallNode functionCallNode = (FunctionCallNode)node;
            string           functionToCall   = functionCallNode.functionName();

            //ActivationFrame evalFrame = activationFrameStack.pop();
            bool isPrimitive = EvaluatePrimitives.evalIfPrimitive(node, activationFrame.peek(), callback);

            //activationFrameStack.push( evalFrame );
            if (isPrimitive)
            {
                return(new List <>());
            }

            // main should only be called from the compliationUnit
            if (functionCallNode.Equals(mainFunctionName))
            {
                return(new List <>());
            }

            FunctionDeclNode functionDeclNode = (FunctionDeclNode)functionNodeMap[functionToCall];

            if (functionDeclNode != null)
            {
                ActivationFrame frame = new ActivationFrame();
                frame.frameName = functionToCall;

                IList <VariableNode>            sourceVariables = new List <VariableNode>();
                IList <VariableDeclarationNode> targetVariables = new List <VariableDeclarationNode>();

                foreach (Node v in node.Instructions)
                {
                    if (v is VariableNode)
                    {
                        sourceVariables.Add((VariableNode)v);
                    }
                }

                foreach (Node v in functionDeclNode.Instructions)
                {
                    if (v is VariableDeclarationNode)
                    {
                        targetVariables.Add((VariableDeclarationNode)v);
                    }
                }

                if (sourceVariables.Count != targetVariables.Count)
                {
                    throw new Exception("Source and target variable count do not match");
                }

                // since the function that is getting called can reference the variable using the
                // formal parameters of the function this code will match the calling functions data
                // with the target calling functions variable name.
                for (int i = 0; i < sourceVariables.Count; i++)
                {
                    VariableNode variableNode = (VariableNode)targetVariables[0].Instructions[1];
                    if (variableNode.integralTypeNode == sourceVariables[i].integralTypeNode)
                    {
                        frame.variableSet[variableNode.variableName] = activationFrame.peek().variableSet[sourceVariables[i].variableName];
                    }
                    else
                    {
                        throw new Exception("data types are not the same");
                    }
                }

                activationFrame.push(frame);


                IList <Node> statements = getFunctionStatements(functionDeclNode.Instructions);
                callback.execute(statements);
                activationFrame.pop();

                //activationFrame.push(frame);
                //execute(functionDeclNode.getInstructions());

                return(new List <Node>());
            }
            else
            {
                FinalNode primitiveArg = new FinalNode();
                primitiveArg.DataString = functionToCall;
                PrimitiveNode primitiveNode = new PrimitiveNode();
                primitiveNode.addInst(primitiveArg);

                foreach (Node primArgs in node.Instructions)
                {
                    if (primArgs is VariableNode || primArgs is IntegralTypeNode)
                    {
                        primitiveNode.addInst(primArgs);
                    }
                }

                return(EvaluatePrimitives.evalPrimitives(primitiveNode, activationFrame.peek(), callback));
            }
        }