public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (!CanBuildOutputAst(Properties.Resources.NoFloorTypesAvailable))
            {
                return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) }
            }
            ;

            var args = new List <AssociativeNode>
            {
                AstFactory.BuildStringNode(((Autodesk.Revit.DB.FloorType)Items[SelectedIndex].Item).Name)
            };

            var functionCall = AstFactory.BuildFunctionCall
                               <System.String, Revit.Elements.FloorType>
                                   (Revit.Elements.FloorType.ByName, args);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
    }
Example #2
0
 public BinaryExpressionNode ReplaceWithConstant(BinaryExpressionNode node, string variable, int value)
 {
     variableName = variable;
     newValueNode = AstFactory.BuildIntNode(value);
     return(node.Accept(this) as BinaryExpressionNode);
 }
Example #3
0
 public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
 {
     yield return(AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), inputAstNodes[0]));
 }
#pragma warning disable CS1591

        public UnitScaleNodeModel()
        {
            InPorts.Add(new PortModel(PortType.Input, this, new PortData("nested", "Nest an existing model scale", AstFactory.BuildNullNode())));

            OutPorts.Add(new PortModel(PortType.Output, this, new PortData("unitScale", "Model units per meter")));

            RegisterAllPorts();

            unitScale = UnitScale.defined.Values.FirstOrDefault();
        }
Example #5
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 ||
                Items[0].Name == NoFamilyTypes ||
                SelectedIndex == -1)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var args = new List <AssociativeNode>
            {
                AstFactory.BuildStringNode(Items[SelectedIndex].Name)
            };

            var func         = new Func <string, int>(ViewTemplateParameters.ByName);
            var functionCall = AstFactory.BuildFunctionCall(func, args);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
Example #6
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 ||
                Items[SelectedIndex].Name == "None" ||
                SelectedIndex < 0)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var intNode = AstFactory.BuildPrimitiveNodeFromObject((string)Items[SelectedIndex].Name);
            var assign  = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), intNode);

            return(new List <AssociativeNode> {
                assign
            });
        }
Example #7
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 || Items[0].Name == noSlabEdge || SelectedIndex == -1)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }
            var node = AstFactory.BuildFunctionCall(
                "Revit.Elements.ElementSelector",
                "ByElementId",
                new List <AssociativeNode> {
                AstFactory.BuildIntNode(((SlabEdgeType)Items[SelectedIndex].Item).Id.IntegerValue)
            });

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Example #8
0
        //<summary>
        //Cast the selected element to a dynamo node
        //</summary>
        //[IsVisibleInDynamoLibrary(false)]
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            // If there are no elements in the dropdown or the selected Index is invalid return a Null node.
            if (Items.Count == 0 ||
                Items[0].Name == "No types found" ||
                SelectedIndex == -1 || Items[SelectedIndex].Name == "none")
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            // Cast the selected object to a Revit Element and get its Id
            var id = ((Autodesk.Revit.DB.Element)Items[SelectedIndex].Item).Id;

            // Select the element using the elementIds Integer Value
            var node = AstFactory.BuildFunctionCall("Revit.Elements.ElementSelector", "ByElementId",
                                                    new List <AssociativeNode> {
                AstFactory.BuildIntNode(id.IntegerValue)
            });

            // Return the selected element
            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Example #9
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 ||
                Items[0].Name == noFamilyParameters ||
                SelectedIndex == -1)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildStringNode((string)Items[SelectedIndex].Item)) });
        }
Example #10
0
        private void _CompileToAstNodes(NodeModel node, List <AssociativeNode> resultList, bool isDeltaExecution)
        {
            var inputAstNodes = new List <AssociativeNode>();

            foreach (int index in Enumerable.Range(0, node.InPortData.Count))
            {
                Tuple <int, NodeModel> inputTuple;

                if (node.TryGetInput(index, out inputTuple))
                {
                    int             outputIndexOfInput = inputTuple.Item1;
                    NodeModel       inputModel         = inputTuple.Item2;
                    AssociativeNode inputNode          = inputModel.GetAstIdentifierForOutputIndex(outputIndexOfInput);

#if DEBUG
                    Validity.Assert(inputNode != null,
                                    "Shouldn't have null nodes in the AST list");
#endif
                    inputAstNodes.Add(inputNode);
                }
                else
                {
                    PortData port = node.InPortData[index];
                    inputAstNodes.Add(
                        port.HasDefaultValue
                            ? AstFactory.BuildPrimitiveNodeFromObject(port.DefaultValue)
                            : new NullNode());
                }
            }

            //TODO: This should do something more than just log a generic message. --SJE
            if (node.State == ElementState.Error)
            {
                dynSettings.DynamoLogger.Log("Error in Node. Not sent for building and compiling");
            }

            if (isDeltaExecution)
            {
                OnAstNodeBuilding(node.GUID);
            }

#if DEBUG
            Validity.Assert(!inputAstNodes.Any((n) => n == null),
                            "Shouldn't have null nodes in the AST list");
#endif

            IEnumerable <AssociativeNode> astNodes = node.BuildAst(inputAstNodes);

            if (dynSettings.Controller.DebugSettings.VerboseLogging)
            {
                foreach (var n in astNodes)
                {
                    dynSettings.DynamoLogger.Log(n.ToString());
                }
            }

            if (null == astNodes)
            {
                resultList.AddRange(new AssociativeNode[0]);
            }
            else if (isDeltaExecution)
            {
                OnAstNodeBuilt(node.GUID, astNodes);
                resultList.AddRange(astNodes);
            }
            else //Inside custom node compilation.
            {
                bool notified = false;
                foreach (var item in astNodes)
                {
                    if (item is FunctionDefinitionNode)
                    {
                        if (!notified)
                        {
                            OnAstNodeBuilding(node.GUID);
                        }
                        notified = true;
                        //Register the function node in global scope with Graph Sync data,
                        //so that we don't have a function definition inside the function def
                        //of custom node.
                        OnAstNodeBuilt(node.GUID, new AssociativeNode[] { item });
                    }
                    else
                    {
                        resultList.Add(item);
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        ///     Compiles a collection of Dynamo nodes into a function definition for a custom node.
        /// </summary>
        /// <param name="def"></param>
        /// <param name="funcBody"></param>
        /// <param name="outputs"></param>
        /// <param name="parameters"></param>
        public void CompileCustomNodeDefinition(
            CustomNodeDefinition def, IEnumerable <NodeModel> funcBody, List <AssociativeNode> outputs,
            IEnumerable <string> parameters)
        {
            OnAstNodeBuilding(def.FunctionId);

            var functionBody = new CodeBlockNode();

            functionBody.Body.AddRange(CompileToAstNodes(funcBody, false));

            if (outputs.Count > 1)
            {
                /* rtn_array = {};
                 * rtn_array[key0] = out0;
                 * rtn_array[key1] = out1;
                 * ...
                 * return = rtn_array;
                 */

                // return array, holds all outputs
                string rtnName = "__temp_rtn_" + def.FunctionId.ToString().Replace("-", String.Empty);
                functionBody.Body.Add(
                    AstFactory.BuildAssignment(
                        AstFactory.BuildIdentifier(rtnName),
                        AstFactory.BuildExprList(new List <string>())));

                // indexers for each output
                IEnumerable <AssociativeNode> indexers = def.ReturnKeys != null
                    ? def.ReturnKeys.Select(AstFactory.BuildStringNode) as IEnumerable <AssociativeNode>
                    : Enumerable.Range(0, outputs.Count).Select(AstFactory.BuildIntNode);

                functionBody.Body.AddRange(
                    outputs.Zip(
                        indexers,
                        (outputId, indexer) => // for each outputId and return key
                        // pack the output into the return array
                        AstFactory.BuildAssignment(AstFactory.BuildIdentifier(rtnName, indexer), outputId)));

                // finally, return the return array
                functionBody.Body.Add(AstFactory.BuildReturnStatement(AstFactory.BuildIdentifier(rtnName)));
            }
            else
            {
                // For single output, directly return that identifier or null.
                AssociativeNode returnValue = outputs.Count == 1 ? outputs[0] : new NullNode();
                functionBody.Body.Add(AstFactory.BuildReturnStatement(returnValue));
            }

            Type allTypes = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar);

            //Create a new function definition
            var functionDef = new FunctionDefinitionNode
            {
                Name      = def.FunctionName.Replace("-", string.Empty),
                Signature =
                    new ArgumentSignatureNode
                {
                    Arguments =
                        parameters.Select(param => AstFactory.BuildParamNode(param, allTypes)).ToList()
                },
                FunctionBody = functionBody,
                ReturnType   = allTypes
            };

            OnAstNodeBuilt(def.FunctionId, new[] { functionDef });
        }
Example #12
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (!HasConnectedInput(0))
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }
            var sliderValue  = AstFactory.BuildDoubleNode(SliderValue);
            var functionCall =
                AstFactory.BuildFunctionCall(
                    new Func <double, double, double>(SampleFunctions.MultiplyTwoNumbers),
                    new List <AssociativeNode> {
                inputAstNodes[0], sliderValue
            });

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
Example #13
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (!CanBuildOutputAst(noTypesMessage))
            {
                return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) }
            }
            ;

            var node = AstFactory.BuildFunctionCall(
                "Revit.Elements.ElementSelector",
                "ByElementId",
                new List <AssociativeNode>
            {
                AstFactory.BuildIntNode(((Element)Items[SelectedIndex].Item).Id.IntegerValue)
            });

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
    }
Example #14
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (!CanBuildOutputAst(Properties.Resources.NoWallTypesAvailable))
            {
                return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) }
            }
            ;

            var args = new List <AssociativeNode>
            {
                AstFactory.BuildStringNode(((Revit.Elements.PerformanceAdviserRule)Items[SelectedIndex].Item).RuleId.ToString())
            };
            var functionCall = AstFactory.BuildFunctionCall("Revit.Elements.PerformanceAdviserRule",
                                                            "ById",
                                                            args);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
    }
Example #15
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            Func <string, string[], object[], object> backingMethod = DSCore.Math.EvaluateFormula;

            // Format input names to be used as function parameters
            var inputs = InPorts.Select(x => x.Name.Replace(' ', '_')).ToList();


            /*  def formula_partial(<params>) {
             *    return = DSCore.Formula.Evaluate(<FormulaString>, <InPortData Names>, <params>);
             *  }
             */

            var functionDef = new FunctionDefinitionNode
            {
                Name      = "__formula_" + AstIdentifierGuid,
                Signature =
                    new ArgumentSignatureNode
                {
                    Arguments = inputs.Select(AstFactory.BuildParamNode).ToList()
                },
                ReturnType   = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Var),
                FunctionBody =
                    new CodeBlockNode
                {
                    Body =
                        new List <AssociativeNode>
                    {
                        AstFactory.BuildReturnStatement(
                            AstFactory.BuildFunctionCall(
                                backingMethod,
                                new List <AssociativeNode>
                        {
                            AstFactory.BuildStringNode(FormulaString),
                            AstFactory.BuildExprList(
                                InPorts.Select(
                                    x =>
                                    AstFactory.BuildStringNode(x.Name) as
                                    AssociativeNode).ToList()),
                            AstFactory.BuildExprList(
                                inputs.Select(AstFactory.BuildIdentifier)
                                .Cast <AssociativeNode>()
                                .ToList())
                        }))
                    }
                }
            };

            if (IsPartiallyApplied)
            {
                return(new AssociativeNode[]
                {
                    functionDef,
                    AstFactory.BuildAssignment(
                        GetAstIdentifierForOutputIndex(0),
                        AstFactory.BuildFunctionObject(
                            functionDef.Name,
                            InPorts.Count,
                            Enumerable.Range(0, InPorts.Count).Where(index => InPorts[index].IsConnected),
                            inputAstNodes))
                });
            }
            else
            {
                UseLevelAndReplicationGuide(inputAstNodes);

                return(new AssociativeNode[]
                {
                    functionDef,
                    AstFactory.BuildAssignment(
                        GetAstIdentifierForOutputIndex(0),
                        AstFactory.BuildFunctionCall(
                            functionDef.Name,
                            inputAstNodes))
                });
            }
        }
Example #16
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 ||
                Items[0].Name == noWallTypes ||
                SelectedIndex == -1)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var args = new List <AssociativeNode>
            {
                AstFactory.BuildStringNode(((Autodesk.Revit.DB.WallType)Items[SelectedIndex].Item).Name)
            };
            var functionCall = AstFactory.BuildFunctionCall("Revit.Elements.WallType",
                                                            "ByName",
                                                            args);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
Example #17
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            var functionCall = AstFactory.BuildFunctionCall(new Func <string, string>(Web.WebRequestByUrl), inputAstNodes);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
Example #18
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 ||
                Items[0].Name == noFamilyTypes ||
                SelectedIndex == -1)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var args = new List <AssociativeNode>
            {
                AstFactory.BuildStringNode(((FamilySymbol)Items[SelectedIndex].Item).Family.Name),
                AstFactory.BuildStringNode(((FamilySymbol)Items[SelectedIndex].Item).Name)
            };

            var functionCall = AstFactory.BuildFunctionCall
                               <System.String, System.String, Revit.Elements.FamilySymbol>
                                   (Revit.Elements.FamilySymbol.ByFamilyNameAndTypeName, args);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAsNodes)
        {
            if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any() || !InPorts[2].Connectors.Any() || !InPorts[3].Connectors.Any())
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var functionCall =
                AstFactory.BuildFunctionCall(
                    new Func <Point, Point, Point, Point, Surface>(NodeModelsEssentialsFunctions.SurfaceFrom4Points),
                    new List <AssociativeNode> {
                inputAsNodes[0], inputAsNodes[1], inputAsNodes[2], inputAsNodes[3]
            });

            // Return an assigment of the generated Ast function call to output node 0
            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
Example #20
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            GeometryObject geob       = null;
            string         stableRep  = string.Empty;
            var            dbDocument = DocumentManager.Instance.CurrentDBDocument;

            if (SelectedElement == null || dbDocument == null)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            if (SelectedElement.UVPoint == null)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var pt = SelectedElement.UVPoint;

            //this is a selected point on a face
            var ptArgs = new List <AssociativeNode>()
            {
                AstFactory.BuildDoubleNode(pt.U),
                AstFactory.BuildDoubleNode(pt.V)
            };

            AssociativeNode node = AstFactory.BuildFunctionCall
                                   (
                "Autodesk.DesignScript.Geometry.UV",
                "ByCoordinates",
                ptArgs
                                   );

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Example #21
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(
            List <AssociativeNode> inputAstNodes)
        {
            if (!InPorts[0].IsConnected || !InPorts[1].IsConnected)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            double unitsMM = Conversions.ConversionDictionary[SelectedExportedUnit] * 1000.0;

            var geometryListNode = inputAstNodes[0];
            var filePathNode     = inputAstNodes[1];
            var unitsMMNode      = AstFactory.BuildDoubleNode(unitsMM);

            AssociativeNode node = null;

            node = AstFactory.BuildFunctionCall(
                new Func <IEnumerable <Geometry>, string, double, string>(Geometry.ExportToSAT),
                new List <AssociativeNode> {
                geometryListNode, filePathNode, unitsMMNode
            });

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) });
        }
Example #22
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            this.ClearErrorsAndWarnings();


            if (SelectedItems == null || hasBeenDeleted)
            {
                //SelectedItems = new Dictionary<string, DMLocator>();
                _locatorLstNode      = AstFactory.BuildNullNode();
                _SelectedNameLstNode = AstFactory.BuildNullNode();
                // _mayaLocator = AstFactory.BuildNullNode();
                hasBeenDeleted = false;
                //return Enumerable.Empty<AssociativeNode>();
            }
            else
            {
                if (SelectedItems.Count > 0)
                {
                    //only rebuild the entire list of geom if needed. otherwise this has been created and is built and updated as needed on only the geometry that has changed
                    if (!isFromUpdate)
                    {
                        dynamoObject = new Dictionary <string, AssociativeNode>(SelectedItems.Count);
                        locatorName  = new Dictionary <string, AssociativeNode>(SelectedItems.Count);
                        //mayaLocator = new Dictionary<string, AssociativeNode>(SelectedItems.Count);

                        foreach (var dag in SelectedItems.Values)
                        {
                            buildAstNodes(dag.dagName);
                        }
                    }


                    _locatorLstNode      = AstFactory.BuildExprList(dynamoObject.Values.ToList());
                    _SelectedNameLstNode = AstFactory.BuildExprList(locatorName.Values.ToList());
                    //_mayaLocator = AstFactory.BuildExprList(mayaLocator.Values.ToList());
                }
                else
                {
                    _locatorLstNode = AstFactory.BuildNullNode();
                }
            }

            isFromUpdate = false;

            return(new[]
            {
                AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), _locatorLstNode),
                AstFactory.BuildAssignment(AstFactory.BuildIdentifier(AstIdentifierBase + "_dummy"),
                                           VMDataBridge.DataBridge.GenerateBridgeDataAst(GUID.ToString(), AstFactory.BuildExprList(inputAstNodes))),

                AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(1), _SelectedNameLstNode),
                AstFactory.BuildAssignment(AstFactory.BuildIdentifier(AstIdentifierBase + "_dummy"),
                                           VMDataBridge.DataBridge.GenerateBridgeDataAst(GUID.ToString(), AstFactory.BuildExprList(inputAstNodes))),
            });
        }
Example #23
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 ||
                Items[0].Name == NoFamilyTypes ||
                SelectedIndex == -1)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var args = new List <AssociativeNode>
            {
                AstFactory.BuildStringNode(Items[SelectedIndex].Name)
            };

            var func         = new Func <string, Autodesk.Revit.DB.FilterStringRuleEvaluator>(archilab.Utilities.FilterStringRuleEvaluator.ByName);
            var functionCall = AstFactory.BuildFunctionCall(func, args);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) });
        }
Example #24
0
 public override IdentifierNode GetAstIdentifierForOutputIndex(int outputIndex)
 {
     return
         (AstFactory.BuildIdentifier(
              InputSymbol == null ? AstIdentifierBase : InputSymbol + "__" + AstIdentifierBase));
 }
Example #25
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (Items.Count == 0 ||
                Items[SelectedIndex].Name == "Select Plate Corener Cut Type..." ||
                SelectedIndex < 0)
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }

            var intNode = AstFactory.BuildIntNode((long)Items[SelectedIndex].Item);
            var assign  = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), intNode);

            return(new List <AssociativeNode> {
                assign
            });
        }
Example #26
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            var doubleNode = AstFactory.BuildDoubleNode(Value);

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), doubleNode) });
        }
Example #27
0
        public override IEnumerable <AssociativeNode> BuildOutputAstInScope(List <AssociativeNode> inputAstNodes, bool verboseLogging, AstBuilder builder)
        {
            // This function will compile IF node to the following format:
            //
            //     cond = ...;
            //     v = [Imperative]
            //     {
            //         if (cond) {
            //             return = [Associative] {
            //                 ...
            //             }
            //         }
            //         else {
            //             return = [Associative] {
            //                 ...
            //             }
            //         }
            //     }
            //

            var astsInTrueBranch  = GetAstsForBranch(1, inputAstNodes, verboseLogging, builder);
            var astsInFalseBranch = GetAstsForBranch(2, inputAstNodes, verboseLogging, builder);

            // if (cond) {
            //     return = [Associative] {...}
            // }
            var ifBlock = new LanguageBlockNode
            {
                codeblock     = new LanguageCodeBlock(Language.Associative),
                CodeBlockNode = new CodeBlockNode {
                    Body = astsInTrueBranch
                }
            };
            var ifBranch = AstFactory.BuildReturnStatement(ifBlock).ToImperativeAST();

            // else {
            //     return = [Associative] { ... }
            // }
            var elseBlock = new LanguageBlockNode
            {
                codeblock     = new LanguageCodeBlock(Language.Associative),
                CodeBlockNode = new CodeBlockNode {
                    Body = astsInFalseBranch
                }
            };
            var elseBranch = AstFactory.BuildReturnStatement(elseBlock).ToImperativeAST();

            var ifelseStatement = new ProtoCore.AST.ImperativeAST.IfStmtNode()
            {
                IfExprNode = inputAstNodes[0].ToImperativeAST(),
                IfBody     = new List <ProtoCore.AST.ImperativeAST.ImperativeNode> {
                    ifBranch
                },
                ElseBody = new List <ProtoCore.AST.ImperativeAST.ImperativeNode> {
                    elseBranch
                }
            };

            // thisVariable = [Imperative]
            // {
            //     ...
            // }
            var outerBlock = new LanguageBlockNode
            {
                codeblock     = new LanguageCodeBlock(Language.Imperative),
                CodeBlockNode = new ProtoCore.AST.ImperativeAST.CodeBlockNode
                {
                    Body = new List <ProtoCore.AST.ImperativeAST.ImperativeNode> {
                        ifelseStatement
                    }
                }
            };

            var thisVariable = GetAstIdentifierForOutputIndex(0);
            var assignment   = AstFactory.BuildAssignment(thisVariable, outerBlock);

            return(new AssociativeNode[]
            {
                assignment
            });
        }
Example #28
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (!HasConnectedInput(0) && !HasConnectedInput(1) && !HasConnectedInput(2))
            {
                return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) });
            }
            AssociativeNode buildColorRangeNode = null;

            // If either of the first two inputs does not have a connector
            // then build a default color range.
            if (!HasConnectedInput(0) || !HasConnectedInput(1))
            {
                buildColorRangeNode =
                    AstFactory.BuildFunctionCall(
                        new Func <ColorRange1D>(ColorRange1D.Default),
                        new List <AssociativeNode>());
            }
            else
            {
                buildColorRangeNode =
                    AstFactory.BuildFunctionCall(
                        new Func <List <Color>, List <double>, ColorRange1D>(ColorRange1D.ByColorsAndParameters),
                        new List <AssociativeNode>()
                {
                    inputAstNodes[0], inputAstNodes[1]
                });
            }

            // The last inputAstNode is assumed to be the value.
            var functionCall =
                AstFactory.BuildFunctionCall(
                    new Func <ColorRange1D, double, Color>(ColorRange1D.GetColorAtParameter),
                    new List <AssociativeNode>()
            {
                buildColorRangeNode, inputAstNodes.Last()
            });

            return(new[]
            {
                AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall),
            });
        }
Example #29
0
 /// <summary>
 ///     Returns <see cref="IdentifierNode"/> by passed output index.
 /// </summary>
 /// <param name="outputIndex">Output index.</param>
 public override IdentifierNode GetAstIdentifierForOutputIndex(int outputIndex)
 {
     return
         (AstFactory.BuildIdentifier(
              string.IsNullOrEmpty(name) ? AstIdentifierBase : name + "__" + AstIdentifierBase));
 }
Example #30
0
        public override IEnumerable <AssociativeNode> BuildOutputAst(List <AssociativeNode> inputAstNodes)
        {
            if (!CanBuildOutputAst(noFamilyParameters))
            {
                return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) }
            }
            ;

            return(new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildStringNode((string)Items[SelectedIndex].Item)) });
        }