/// <summary>
        /// Serializes the specified object into a CodeDOM object.
        /// </summary>
        /// <param name="manager">A serialization manager interface that is used during the deserialization process.</param>
        /// <param name="value">The object to serialize.</param>
        /// <returns>A CodeDOM object representing the object that has been serialized.</returns>
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            // Set serialization flag
            bool oldSerializationFlag = false;
            SerializationStatus oldSerializationStatus = SerializationStatus.None;

            Chart chart = value as Chart;

            if (chart != null)
            {
                oldSerializationFlag   = chart.serializing;
                oldSerializationStatus = chart.serializationStatus;

                chart.serializing         = true;
                chart.serializationStatus = SerializationStatus.Saving;
            }

            // Serialize object using the base class serializer
            object            result         = null;
            CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(Chart).BaseType, typeof(CodeDomSerializer));

            if (baseSerializer != null)
            {
                result = baseSerializer.Serialize(manager, value);

                System.CodeDom.CodeStatementCollection statements = result as System.CodeDom.CodeStatementCollection;

                // Sustom serialization of the DataSource property
                if (statements != null && chart != null)
                {
                    // Check if DataSource property is set
                    if (chart.DataSource != null && chart.DataSource is String && ((String)chart.DataSource) != "(none)")
                    {
                        // Add assignment statement for the DataSource property
                        System.CodeDom.CodeExpression targetObject =
                            base.SerializeToExpression(manager, value);
                        if (targetObject != null)
                        {
                            System.CodeDom.CodeAssignStatement assignStatement = new System.CodeDom.CodeAssignStatement(
                                new System.CodeDom.CodePropertyReferenceExpression(targetObject, "DataSource"),
                                new System.CodeDom.CodePropertyReferenceExpression(new System.CodeDom.CodeThisReferenceExpression(), (String)chart.DataSource));
                            statements.Add(assignStatement);
                        }
                    }
                }
            }

            // Clear serialization flag
            if (chart != null)
            {
                chart.serializing         = oldSerializationFlag;
                chart.serializationStatus = oldSerializationStatus;
            }

            return(result);
        }
Esempio n. 2
0
        public static void GetSetDataValueCodeStatement(System.CodeDom.CodeStatementCollection codeStatementCollection, string name, System.CodeDom.CodeExpression valueExp, Type valueType)
        {
            var stat = new System.CodeDom.CodeAssignStatement(
                valueExp,
                new CodeGenerateSystem.CodeDom.CodeCastExpression(
                    valueType,
                    new System.CodeDom.CodeFieldReferenceExpression(
                        new System.CodeDom.CodeVariableReferenceExpression("mDebuggerContext"), name)
                    ));

            codeStatementCollection.Add(stat);
        }
Esempio n. 3
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (element == mCtrlMethodLink_Pre)
            {
                // 正常逻辑执行代码
                if (mCtrlValueElement.HasLink && mCtrlSetValueElement.HasLink)
                {
                    var codeAss = new System.CodeDom.CodeAssignStatement();
                    codeAss.Left = mCtrlValueElement.GetLinkedObject(0, false).GCode_CodeDom_GetValue(mCtrlValueElement.GetLinkedPinControl(0, false), context);

                    if (!mCtrlSetValueElement.GetLinkedObject(0, true).IsOnlyReturnValue)
                    {
                        await mCtrlSetValueElement.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlSetValueElement.GetLinkedPinControl(0, true), context);
                    }

                    string valueTypeStr = mCtrlSetValueElement.GetLinkedObject(0, true).GCode_GetTypeString(mCtrlSetValueElement.GetLinkedPinControl(0, true), context);
                    var    valueType    = mCtrlSetValueElement.GetLinkedObject(0, true).GCode_GetType(mCtrlSetValueElement.GetLinkedPinControl(0, true), context);
                    var    tempValName  = "assign_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id);
                    if (!context.Method.Statements.Contains(mVariableDeclarationStatement))
                    {
                        var type = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueTypeStr);
                        mVariableDeclarationStatement = new System.CodeDom.CodeVariableDeclarationStatement(
                            valueTypeStr,
                            tempValName,
                            CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(type));
                        context.Method.Statements.Insert(0, mVariableDeclarationStatement);
                    }
                    var assignStatement = new System.CodeDom.CodeAssignStatement(
                        new System.CodeDom.CodeVariableReferenceExpression(tempValName),
                        mCtrlSetValueElement.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlSetValueElement.GetLinkedPinControl(0, true), context));
                    codeStatementCollection.Add(assignStatement);

                    // 收集用于调试的数据的代码
                    var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

                    CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlSetValueElement.GetLinkPinKeyName(),
                                                                           new System.CodeDom.CodeVariableReferenceExpression(tempValName),
                                                                           valueTypeStr, context);
                    // 调试用代码
                    var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);
                    // 设置数据代码
                    CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, mCtrlSetValueElement.GetLinkPinKeyName(),
                                                                        new System.CodeDom.CodeVariableReferenceExpression(tempValName),
                                                                        valueType);
                    if (!mCtrlValueElement.GetLinkedObject(0, false).IsOnlyReturnValue)
                    {
                        await mCtrlValueElement.GetLinkedObject(0, false).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, element, context);
                    }
                    codeAss.Right = new CodeGenerateSystem.CodeDom.CodeCastExpression(mCtrlValueElement.GetLinkedObject(0, false).GCode_GetType(mCtrlValueElement.GetLinkedPinControl(0, false), context),
                                                                                      new System.CodeDom.CodeVariableReferenceExpression(tempValName));

                    codeStatementCollection.Add(codeAss);

                    // 收集结果代码
                    CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlValueElement.GetLinkPinKeyName(),
                                                                           mCtrlValueElement.GetLinkedObject(0, false).GCode_CodeDom_GetValue(mCtrlValueElement.GetLinkedPinControl(0, false), context),
                                                                           mCtrlValueElement.GetLinkedObject(0, false).GCode_GetTypeString(mCtrlValueElement.GetLinkedPinControl(0, false), context), context);
                    CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
                }

                if (context.GenerateNext)
                {
                    if (mCtrlMethodLink_Next.HasLink)
                    {
                        await mCtrlMethodLink_Next.GetLinkedObject(0, false).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlMethodLink_Next.GetLinkedPinControl(0, false), context);
                    }
                }
            }
        }
Esempio n. 4
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (!mCtrlValue1.HasLink)
            {
                return;
            }

            // 计算结果
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                var valueType = GCode_GetTypeString(mCtrlResultLink, context);
                var type      = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType);
                mVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement(
                    valueType,
                    GCode_GetValueName(mCtrlResultLink, context),
                    CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(type));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            // 参数1
            var linkObj1 = mCtrlValue1.GetLinkedObject(0, true);
            var linkElm1 = mCtrlValue1.GetLinkedPinControl(0, true);

            if (!linkObj1.IsOnlyReturnValue)
            {
                await linkObj1.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm1, context);
            }

            System.CodeDom.CodeExpression valueExp1 = null;
            var valueType1    = typeof(bool);
            var valueType1Str = valueType1.FullName;

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(false));
                    valueExp1 = condition;
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp1 = condition;
                }
            }
            else
            {
                var tempValueName1 = "InverterControl_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value1";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value1))
                {
                    mVariableDeclarationStatement_Value1 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType1Str,
                        tempValueName1,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType1Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value1);
                }


                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(false));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityEquality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                valueExp1 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName1);
            }
            //var valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            // 调试用代码
            var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);

            // 设置数据代码
            if (!linkObj1.Pin_UseOrigionParamName(this.mCtrlValue1))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1);
            }
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);

            if (element == mCtrlResultLink)
            {
                // 创建结果并赋值
                if (mAssignStatement == null)
                {
                    mAssignStatement      = new System.CodeDom.CodeAssignStatement();
                    mAssignStatement.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
                }
                mAssignStatement.Right = valueExp1;

                if (codeStatementCollection.Contains(mAssignStatement))
                {
                    //var assign = new System.CodeDom.CodeAssignStatement(GCode_CodeDom_GetValue(null) , InverterControlExp);
                    //codeStatementCollection.Add(assign);
                }
                else
                {
                    codeStatementCollection.Add(mAssignStatement);
                }

                debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlResultLink.GetLinkPinKeyName(), GCode_CodeDom_GetValue(mCtrlResultLink, context), GCode_GetTypeString(mCtrlResultLink, context), context);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
            }
        }
Esempio n. 5
0
 protected abstract void GenerateAssignStatement(System.CodeDom.CodeAssignStatement e);
Esempio n. 6
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (!mCtrlValue1.HasLink || !mCtrlValue2.HasLink)
            {
                return;
            }

            // 计算结果
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                var valueType = GCode_GetTypeString(mCtrlResultLink, context);
                var type      = EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType);
                mVariableDeclaration = new System.CodeDom.CodeVariableDeclarationStatement(
                    valueType,
                    GCode_GetValueName(mCtrlResultLink, context),
                    CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(type));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            // 参数1
            var linkObj1 = mCtrlValue1.GetLinkedObject(0, true);
            var linkElm1 = mCtrlValue1.GetLinkedPinControl(0, true);

            if (!linkObj1.IsOnlyReturnValue)
            {
                await linkObj1.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm1, context);
            }

            System.CodeDom.CodeExpression valueExp1 = null;
            var valueType1Str = linkObj1.GCode_GetTypeString(linkElm1, context);
            var valueType1    = linkObj1.GCode_GetType(linkElm1, context);

            if (CSParam.ConstructParam == "&&" || CSParam.ConstructParam == "||")
            {
                valueType1Str = "System.Boolean";
                valueType1    = typeof(bool);
            }
            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp1 = condition;
                }
                else
                {
                    valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);
                }
            }
            else
            {
                var tempValueName1 = "arithmetic_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value1";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value1))
                {
                    mVariableDeclarationStatement_Value1 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType1Str,
                        tempValueName1,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType1Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value1);
                }


                if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    linkObj1.GCode_CodeDom_GetValue(linkElm1, context)));
                }
                else if (linkElm1.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj1.GCode_CodeDom_GetValue(linkElm1, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    condition));
                }
                else
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName1),
                                                    linkObj1.GCode_CodeDom_GetValue(linkElm1, context)));
                }
                valueExp1 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName1);
            }
            //var valueExp1 = linkObj1.GCode_CodeDom_GetValue(linkElm1, context);

            // 参数2
            var linkObj2 = mCtrlValue2.GetLinkedObject(0, true);
            var linkElm2 = mCtrlValue2.GetLinkedPinControl(0, true);

            if (!linkObj2.IsOnlyReturnValue)
            {
                await linkObj2.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, linkElm2, context);
            }

            System.CodeDom.CodeExpression valueExp2 = null;
            var valueType2Str = linkObj2.GCode_GetTypeString(linkElm2, context);
            var valueType2    = linkObj2.GCode_GetType(linkElm2, context);

            if (CSParam.ConstructParam == "&&" || CSParam.ConstructParam == "||")
            {
                valueType2Str = "System.Boolean";
                valueType2    = typeof(bool);
            }
            if (linkObj2.Pin_UseOrigionParamName(linkElm2))
            {
                if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);
                }
                else if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj2.GCode_CodeDom_GetValue(linkElm2, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    valueExp2 = condition;
                }
                else
                {
                    valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);
                }
            }
            else
            {
                var tempValueName2 = "arithmetic_" + EngineNS.Editor.Assist.GetValuedGUIDString(this.Id) + "_Value2";
                if (!context.Method.Statements.Contains(mVariableDeclarationStatement_Value2))
                {
                    mVariableDeclarationStatement_Value2 = new System.CodeDom.CodeVariableDeclarationStatement(
                        valueType2Str,
                        tempValueName2,
                        CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(EngineNS.Rtti.RttiHelper.GetTypeFromTypeFullName(valueType2Str)));
                    context.Method.Statements.Insert(0, mVariableDeclarationStatement_Value2);
                }


                if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Bool)
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    linkObj2.GCode_CodeDom_GetValue(linkElm2, context)));
                }
                else if (linkElm2.GetLinkType(0, true) == CodeGenerateSystem.Base.enLinkType.Class)
                {
                    var condition = new System.CodeDom.CodeBinaryOperatorExpression(linkObj2.GCode_CodeDom_GetValue(linkElm2, context),
                                                                                    System.CodeDom.CodeBinaryOperatorType.IdentityInequality,
                                                                                    new System.CodeDom.CodePrimitiveExpression(null));
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    condition));
                }
                else
                {
                    codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(
                                                    new System.CodeDom.CodeTypeReferenceExpression(tempValueName2),
                                                    linkObj2.GCode_CodeDom_GetValue(linkElm2, context)));
                }
                valueExp2 = new System.CodeDom.CodeVariableReferenceExpression(tempValueName2);
            }
            //var valueExp2 = linkObj2.GCode_CodeDom_GetValue(linkElm2, context);

            // 运算
            var arithmeticExp = new System.CodeDom.CodeBinaryOperatorExpression();

            arithmeticExp.Left  = valueExp1;
            arithmeticExp.Right = valueExp2;
            switch (CSParam.ConstructParam)
            {
            case "+":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Add;
                break;

            case "-":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Subtract;
                break;

            case "×":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Multiply;
                break;

            case "÷":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.Divide;
                break;

            case "&&":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BooleanAnd;
                break;

            case "||":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BooleanOr;
                break;

            case "&":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BitwiseAnd;
                break;

            case "|":
                arithmeticExp.Operator = System.CodeDom.CodeBinaryOperatorType.BitwiseOr;
                break;
            }

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            if (linkObj1.Pin_UseOrigionParamName(linkElm1))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1Str, context);
            }
            if (linkObj2.Pin_UseOrigionParamName(linkElm2))
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2Str, context);
            }
            else
            {
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2Str, context);
            }
            // 调试用代码
            var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id);

            // 设置数据代码
            if (!linkObj1.Pin_UseOrigionParamName(this.mCtrlValue1))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue1.GetLinkPinKeyName(), valueExp1, valueType1);
            }
            if (!linkObj2.Pin_UseOrigionParamName(this.mCtrlValue2))
            {
                CodeDomNode.BreakPoint.GetSetDataValueCodeStatement(breakCondStatement.TrueStatements, this.mCtrlValue2.GetLinkPinKeyName(), valueExp2, valueType2);
            }
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);

            if (element == mCtrlResultLink)
            {
                // 创建结果并赋值
                if (mAssignStatement == null)
                {
                    mAssignStatement      = new System.CodeDom.CodeAssignStatement();
                    mAssignStatement.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
                }
                mAssignStatement.Right = arithmeticExp;

                if (codeStatementCollection.Contains(mAssignStatement))
                {
                    //var assign = new System.CodeDom.CodeAssignStatement(GCode_CodeDom_GetValue(null) , arithmeticExp);
                    //codeStatementCollection.Add(assign);
                }
                else
                {
                    codeStatementCollection.Add(mAssignStatement);
                }

                debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlResultLink.GetLinkPinKeyName(), GCode_CodeDom_GetValue(mCtrlResultLink, context), GCode_GetTypeString(mCtrlResultLink, context), context);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
            }
        }
Esempio n. 7
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            if (!mCtrlParamLink_1.HasLink || !mCtrlParamLink_2.HasLink)
            {
                return;
            }

            if (!mCtrlParamLink_1.GetLinkedObject(0, true).IsOnlyReturnValue)
            {
                await mCtrlParamLink_1.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlParamLink_1.GetLinkedPinControl(0, true), context);
            }

            if (!mCtrlParamLink_2.GetLinkedObject(0, true).IsOnlyReturnValue)
            {
                await mCtrlParamLink_2.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlParamLink_2.GetLinkedPinControl(0, true), context);
            }

            var param1Exp = mCtrlParamLink_1.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlParamLink_1.GetLinkedPinControl(0, true), context);
            var param2Exp = mCtrlParamLink_2.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlParamLink_2.GetLinkedPinControl(0, true), context);

            var type1 = mCtrlParamLink_1.GetLinkedObject(0, true).GCode_GetType(mCtrlParamLink_1.GetLinkedPinControl(0, true), context);
            var type2 = mCtrlParamLink_2.GetLinkedObject(0, true).GCode_GetType(mCtrlParamLink_2.GetLinkedPinControl(0, true), context);

            if (type1.IsEnum && !type2.IsEnum)
            {
                param1Exp = new CodeGenerateSystem.CodeDom.CodeCastExpression(type2, param1Exp);
            }
            else if (!type1.IsEnum && type2.IsEnum)
            {
                param2Exp = new CodeGenerateSystem.CodeDom.CodeCastExpression(type1, param2Exp);
            }

            var compareExp = new System.CodeDom.CodeBinaryOperatorExpression();

            compareExp.Left  = param1Exp;
            compareExp.Right = param2Exp;

            switch (CSParam.ConstructParam)
            {
            case ">":
                compareExp.Operator = System.CodeDom.CodeBinaryOperatorType.GreaterThan;
                break;

            case "=":
            case "==":
                compareExp.Operator = System.CodeDom.CodeBinaryOperatorType.ValueEquality;
                break;

            case "<":
                compareExp.Operator = System.CodeDom.CodeBinaryOperatorType.LessThan;
                break;

            case "≥":
                compareExp.Operator = System.CodeDom.CodeBinaryOperatorType.GreaterThanOrEqual;
                break;

            case "≤":
                compareExp.Operator = System.CodeDom.CodeBinaryOperatorType.LessThanOrEqual;
                break;

            case "≠":
                compareExp.Operator = System.CodeDom.CodeBinaryOperatorType.IdentityInequality;
                break;
            }

            if (!context.Method.Statements.Contains(mVariableDeclarationStatement))
            {
                mVariableDeclarationStatement = new System.CodeDom.CodeVariableDeclarationStatement(typeof(bool), GCode_GetValueName(null, context));
                context.Method.Statements.Insert(0, mVariableDeclarationStatement);
            }
            if (!codeStatementCollection.Contains(mVariableAssignStatement))
            {
                //mVariableDeclarationStatement = new System.CodeDom.CodeVariableDeclarationStatement(typeof(bool), GCode_GetValueName(null, context), compareExp);
                mVariableAssignStatement = new System.CodeDom.CodeAssignStatement(GCode_CodeDom_GetValue(null, context), compareExp);
                codeStatementCollection.Add(mVariableAssignStatement);

                // 收集用于调试的数据的代码
                var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);
                CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlresultHandle.GetLinkPinKeyName(), GCode_CodeDom_GetValue(null, context), GCode_GetTypeString(null, context), context);
                CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
            }
        }
Esempio n. 8
0
        public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context)
        {
            GetBezierPointsFromCtrl();

            if (!codeClass.Members.Contains(mBezierPointsField))
            {
                // code: private static System.Collections.Generic.List<EngineNS.BezierPointBase> mBezierPoints_XXX = new System.Collections.Generic.List<EngineNS.BezierPointBase>(new BezierPoint[] { new EngineNS.BezierPointBase(), new EngineNS.BezierPointBase() });
                mBezierPointsField.Type       = new System.CodeDom.CodeTypeReference(BezierPointsListType);
                mBezierPointsField.Name       = StaticBezierPointsName;
                mBezierPointsField.Attributes = System.CodeDom.MemberAttributes.Private;
                var arrayCreateExp = new System.CodeDom.CodeArrayCreateExpression();
                arrayCreateExp.CreateType = new System.CodeDom.CodeTypeReference(typeof(EngineNS.BezierPointBase));
                foreach (var bPt in mBezierPoints)
                {
                    var newBPT = new System.CodeDom.CodeObjectCreateExpression();
                    newBPT.CreateType = new System.CodeDom.CodeTypeReference(typeof(EngineNS.BezierPointBase));
                    newBPT.Parameters.Add(new System.CodeDom.CodeObjectCreateExpression(typeof(EngineNS.Vector2),
                                                                                        new System.CodeDom.CodeExpression[] {
                        new System.CodeDom.CodePrimitiveExpression(bPt.Position.X),
                        new System.CodeDom.CodePrimitiveExpression(bPt.Position.Y)
                    }));
                    newBPT.Parameters.Add(new System.CodeDom.CodeObjectCreateExpression(typeof(EngineNS.Vector2),
                                                                                        new System.CodeDom.CodeExpression[] {
                        new System.CodeDom.CodePrimitiveExpression(bPt.ControlPoint.X),
                        new System.CodeDom.CodePrimitiveExpression(bPt.ControlPoint.Y)
                    }));
                    arrayCreateExp.Initializers.Add(newBPT);
                }
                mBezierPointsField.InitExpression = new System.CodeDom.CodeObjectCreateExpression(BezierPointsListType, arrayCreateExp);
                codeClass.Members.Add(mBezierPointsField);
            }

            // 判断5个输入链接是否需要生成代码
            if (mCtrlValueInputHandle.HasLink)
            {
                if (!mCtrlValueInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueYMaxInputHandle.HasLink)
            {
                if (!mCtrlValueYMaxInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueYMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueYMaxInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueYMinInputHandle.HasLink)
            {
                if (!mCtrlValueYMinInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueYMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueYMinInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueXMaxInputHandle.HasLink)
            {
                if (!mCtrlValueXMaxInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueXMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueXMaxInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueXMinInputHandle.HasLink)
            {
                if (!mCtrlValueXMinInputHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueXMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueXMinInputHandle.GetLinkedPinControl(0, true), context);
                }
            }

            if (mCtrlValueXLoopHandle.HasLink)
            {
                if (!mCtrlValueXLoopHandle.GetLinkedObject(0, true).IsOnlyReturnValue)
                {
                    await mCtrlValueXLoopHandle.GetLinkedObject(0, true).GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, mCtrlValueXLoopHandle.GetLinkedPinControl(0, true), context);
                }
            }

            // 自身代码生成
            if (!context.Method.Statements.Contains(mVariableDeclaration))
            {
                // 声明
                mVariableDeclaration.Type           = new System.CodeDom.CodeTypeReference(typeof(double));
                mVariableDeclaration.Name           = GCode_GetValueName(null, context);
                mVariableDeclaration.InitExpression = CodeGenerateSystem.Program.GetDefaultValueExpressionFromType(typeof(double));
                context.Method.Statements.Insert(0, mVariableDeclaration);
            }

            var assignExp = new System.CodeDom.CodeAssignStatement();

            assignExp.Left = new System.CodeDom.CodeVariableReferenceExpression(GCode_GetValueName(null, context));
            var classType = mTemplateClassInstance.GetType();

            System.CodeDom.CodeExpression minXExp, maxXExp, minYExp, maxYExp, isXLoopExp;
            if (mCtrlValueXMinInputHandle.HasLink)
            {
                minXExp = mCtrlValueXMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueXMinInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("XMin");
                var xMin = pro.GetValue(mTemplateClassInstance);
                minXExp = new System.CodeDom.CodePrimitiveExpression(xMin);
            }

            if (mCtrlValueXMaxInputHandle.HasLink)
            {
                maxXExp = mCtrlValueXMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueXMaxInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("XMax");
                var xMax = pro.GetValue(mTemplateClassInstance);
                maxXExp = new System.CodeDom.CodePrimitiveExpression(xMax);
            }

            if (mCtrlValueYMinInputHandle.HasLink)
            {
                minYExp = mCtrlValueYMinInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueYMinInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("YMin");
                var yMin = pro.GetValue(mTemplateClassInstance);
                minYExp = new System.CodeDom.CodePrimitiveExpression(yMin);
            }

            if (mCtrlValueYMaxInputHandle.HasLink)
            {
                maxYExp = mCtrlValueYMaxInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueYMaxInputHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro  = classType.GetProperty("YMax");
                var yMax = pro.GetValue(mTemplateClassInstance);
                maxYExp = new System.CodeDom.CodePrimitiveExpression(yMax);
            }

            if (mCtrlValueXLoopHandle.HasLink)
            {
                isXLoopExp = mCtrlValueXLoopHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueXLoopHandle.GetLinkedPinControl(0, true), context);
            }
            else
            {
                var pro     = classType.GetProperty("XLoop");
                var isXLoop = pro.GetValue(mTemplateClassInstance);
                isXLoopExp = new System.CodeDom.CodePrimitiveExpression(isXLoop);
            }

            // code: EngineNS.BezierCalculate.ValueOnBezier(mBezierPoints_XXX, XPos);
            assignExp.Right = new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(
                new System.CodeDom.CodeTypeReferenceExpression(typeof(EngineNS.BezierCalculate)),
                "ValueOnBezier",
                new System.CodeDom.CodeExpression[] {
                new System.CodeDom.CodeVariableReferenceExpression(StaticBezierPointsName),                                                         // bezierPtList
                mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueInputHandle.GetLinkedPinControl(0, true), context), // xValue
                minXExp, maxXExp, minYExp, maxYExp,
                new System.CodeDom.CodePrimitiveExpression(0),                                                                                      // MinBezierX
                new System.CodeDom.CodePrimitiveExpression(mBezierWidth),                                                                           // MaxBezierX
                new System.CodeDom.CodePrimitiveExpression(0),                                                                                      // MinBezierY
                new System.CodeDom.CodePrimitiveExpression(mBezierHeight),                                                                          // MaxBezierY
                isXLoopExp                                                                                                                          // bLoopX
            });

            codeStatementCollection.Add(assignExp);

            // 收集用于调试的数据的代码
            var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection);

            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, this.mCtrlValueInputHandle.GetLinkPinKeyName(),
                                                                   mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_CodeDom_GetValue(mCtrlValueInputHandle.GetLinkedPinControl(0, true), context),
                                                                   mCtrlValueInputHandle.GetLinkedObject(0, true).GCode_GetTypeString(mCtrlValueInputHandle.GetLinkedPinControl(0, true), context), context);
            CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, mCtrlValueOutputHandle.GetLinkPinKeyName(),
                                                                   assignExp.Left, GCode_GetTypeString(null, context), context);
            CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes);
        }