private void Handle_Form_Load(object sender, EventArgs e)
        {
            _document = AdnInventorUtilities.InvApplication.ActiveDocument;

            this.KeyPreview = true;
            this.KeyDown   += new KeyEventHandler(LinkParametersForm_KeyDown);

            this.Text = "Link Parameters  [Rule: " + _ruleName + "]";

            _ruleOptionsForm = new RuleOptionsForm();

            //Retrieve rule properties if rule exists
            IiLogicAutomation ruleApi = iLogicUtilities.GetiLogicAutomation();

            iLogicRule rule = ruleApi.GetRule(_document, _ruleName);

            if (rule != null)
            {
                _ruleOptionsForm.FireDep     = rule.FireDependentImmediately;
                _ruleOptionsForm.DontRunAuto = !rule.AutomaticOnParamChange;
                //_ruleOptionsForm.UpdateWhenDone =
            }

            _sourceParameterDict = new Dictionary <Parameter, ListViewItem>();
            _targetParameterDict = new Dictionary <Parameter, ListViewItem>();

            _currentParamFilter = ParamFilterEnum.kAll;

            Command.SourceComponent = null;
            Command.TargetComponent = null;

            _mappings = ParameterMappingInfo.GetMappings(_document, _ruleName);
        }
        private void Handle_TargetParameterList_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ParameterInfo)) == false)
            {
                return;
            }

            ParameterInfo parameterInfo = e.Data.GetData(typeof(ParameterInfo)) as ParameterInfo;

            if (parameterInfo == null)
            {
                return;
            }

            System.Drawing.Point pt = _targetParameterList.PointToClient(
                new System.Drawing.Point(e.X, e.Y));

            ListViewItem targetItem = _targetParameterList.GetItemAt(pt.X, pt.Y);

            if (targetItem == null)
            {
                return;
            }

            //Check parameter types
            Parameters TargetParams = AdnInventorUtilities.GetProperty(
                Command.TargetComponent.Definition,
                "Parameters") as Parameters;

            if (TargetParams[targetItem.Text].Value.GetType() != parameterInfo.ParamType)
            {
                System.Windows.Forms.MessageBox.Show("Parameters must have same type in order to be mapped!",
                                                     "Invalid Parameter types",
                                                     MessageBoxButtons.OK,
                                                     MessageBoxIcon.Exclamation);

                return;
            }

            ParameterMappingInfo mapping = new ParameterMappingInfo()
            {
                SourceComponentName = parameterInfo.ComponentName,
                SourceParameterName = parameterInfo.ParameterName,
                TargetComponentName = Command.TargetComponent.Name,
                TargetParameterName = targetItem.Text,
            };

            _newMappings.Add(mapping);

            //Delete existing mapping if any
            DeleteMapping(targetItem.Tag as ParameterMappingInfo);

            targetItem.SubItems[2].Text = mapping.SourceName;
            targetItem.Tag = mapping;

            ValidateButtons();
        }
        private void Handle_BtnApply_Click(object sender, EventArgs e)
        {
            ApplyMappings();

            _mappings = ParameterMappingInfo.GetMappings(_document, _ruleName);

            RefreshTargetParameters();

            ValidateButtons();
        }
Esempio n. 4
0
 public BinaryRetTypeBinder(DynamicMetaObjectBinder operationBinder, PythonConversionBinder conversionBinder) :
     base(new BinderMappingInfo(
              operationBinder,
              ParameterMappingInfo.Parameter(0),
              ParameterMappingInfo.Parameter(1)
              ),
          new BinderMappingInfo(
              conversionBinder,
              ParameterMappingInfo.Action(0)
              )
          )
 {
     _opBinder   = operationBinder;
     _convBinder = conversionBinder;
 }
        private void DeleteMapping(ParameterMappingInfo mapping)
        {
            if (mapping == null)
            {
                return;
            }

            if (_newMappings.Contains(mapping))
            {
                _newMappings.Remove(mapping);
            }
            else
            {
                _erasedMappings.Add(mapping);
            }
        }
        private void RefreshTargetParameters()
        {
            _targetParameterList.Items.Clear();
            _targetParameterDict.Clear();

            if (Command.TargetComponent == null)
            {
                return;
            }

            _newMappings    = new List <ParameterMappingInfo>();
            _erasedMappings = new List <ParameterMappingInfo>();

            ComponentDefinition definition = Command.TargetComponent.Definition;

            Parameters Parameters = AdnInventorUtilities.GetProperty(
                definition,
                "Parameters") as Parameters;

            foreach (Parameter parameter in Parameters)
            {
                ListViewItem newItem = new ListViewItem();

                string value = AdnInventorUtilities.GetStringFromValue(parameter);

                newItem.Text = parameter.Name;
                newItem.SubItems.Add(value);
                newItem.SubItems.Add(string.Empty);
                newItem.ToolTipText = parameter.Name + " = " + value;

                ParameterMappingInfo mapping =
                    _mappings.FirstOrDefault(m => m.TargetComponentName == Command.TargetComponent.Name &&
                                             m.TargetParameterName == parameter.Name);

                if (mapping != null)
                {
                    newItem.SubItems[2].Text = mapping.SourceName;
                    newItem.Tag = mapping;
                }

                _targetParameterList.Items.Add(newItem);
                _targetParameterDict.Add(parameter, newItem);
            }

            ApplyParametersFilter(_targetParameterDict, _targetParameterList, _currentParamFilter);
        }
        private void AutoMapMatchingParams()
        {
            Parameters TargetParams = AdnInventorUtilities.GetProperty(
                Command.TargetComponent.Definition,
                "Parameters") as Parameters;

            foreach (ListViewItem sourceItem in _sourceParameterList.Items)
            {
                foreach (ListViewItem targetItem in _targetParameterList.Items)
                {
                    if (sourceItem.Text != targetItem.Text)
                    {
                        continue;
                    }

                    ParameterInfo parameterInfo = sourceItem.Tag as ParameterInfo;

                    if (TargetParams[targetItem.Text].Value.GetType() != parameterInfo.ParamType)
                    {
                        continue;
                    }

                    ParameterMappingInfo mapping = new ParameterMappingInfo()
                    {
                        SourceComponentName = parameterInfo.ComponentName,
                        SourceParameterName = parameterInfo.ParameterName,
                        TargetComponentName = Command.TargetComponent.Name,
                        TargetParameterName = targetItem.Text,
                    };

                    _newMappings.Add(mapping);

                    //Delete existing mapping if any
                    DeleteMapping(targetItem.Tag as ParameterMappingInfo);

                    targetItem.SubItems[2].Text = mapping.SourceName;
                    targetItem.Tag = mapping;
                }
            }

            ValidateButtons();
        }
Esempio n. 8
0
        internal MSAst.Expression TransformAndDynamicConvert(Expression expression, Type /*!*/ type)
        {
            Debug.Assert(expression != null);

            MSAst.Expression res = expression;

            // Do we need conversion?
            if (!CanAssign(type, expression.Type))
            {
                // ensure we're reduced before we check for dynamic expressions.

                var reduced = expression.Reduce();
                if (reduced is LightDynamicExpression)
                {
                    reduced = reduced.Reduce();
                }

                // Add conversion step to the AST
                MSAst.DynamicExpression    ae  = reduced as MSAst.DynamicExpression;
                ReducableDynamicExpression rde = reduced as ReducableDynamicExpression;

                if ((ae != null && ae.Binder is PythonBinaryOperationBinder) ||
                    (rde != null && rde.Binder is PythonBinaryOperationBinder))
                {
                    // create a combo site which does the conversion
                    PythonBinaryOperationBinder binder;
                    IList <MSAst.Expression>    args;
                    if (ae != null)
                    {
                        binder = (PythonBinaryOperationBinder)ae.Binder;
                        args   = ArrayUtils.ToArray(ae.Arguments);
                    }
                    else
                    {
                        binder = (PythonBinaryOperationBinder)rde.Binder;
                        args   = rde.Args;
                    }

                    ParameterMappingInfo[] infos = new ParameterMappingInfo[args.Count];
                    for (int i = 0; i < infos.Length; i++)
                    {
                        infos[i] = ParameterMappingInfo.Parameter(i);
                    }

                    res = Expression.Dynamic(
                        GlobalParent.PyContext.BinaryOperationRetType(
                            binder,
                            GlobalParent.PyContext.Convert(
                                type,
                                ConversionResultKind.ExplicitCast
                                )
                            ),
                        type,
                        args
                        );
                }
                else
                {
                    res = GlobalParent.Convert(
                        type,
                        ConversionResultKind.ExplicitCast,
                        reduced
                        );
                }
            }
            return(res);
        }