public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             FieldCalculatorCollection calculators = context.Instance as FieldCalculatorCollection;
             if (calculators != null)
             {
                 FieldCalculator ev = (FieldCalculator)value;
                 if (ev == null)
                 {
                     ev           = new FieldCalculator();
                     ev.FieldName = context.PropertyDescriptor.Name;
                 }
                 MathNodeRoot root = ev.GetExpression();
                 if (root == null)
                 {
                     root = new MathNodeRoot();
                     ev.SetExpression(root);
                 }
                 System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
                 rc.X = curPoint.X;
                 rc.Y = curPoint.Y;
                 IMathEditor dlg = root.CreateEditor(rc);
                 dlg.SetScopeMethod(root.ScopeMethod);
                 dlg.MathExpression             = (IMathExpression)root.Clone();
                 dlg.MathExpression.ScopeMethod = root.ScopeMethod;
                 dlg.MathExpression.EnableUndo  = true;
                 if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
                 {
                     root = (MathNodeRoot)dlg.MathExpression;
                     ev   = new FieldCalculator();
                     ev.SetExpression(root);
                     ev.FieldName = context.PropertyDescriptor.Name;
                     value        = ev;
                     calculators.SetItem(ev);
                 }
             }
         }
     }
     return(value);
 }
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         ParameterValue pv = context.Instance as ParameterValue;
         if (pv == null)
         {
             MapItem item = context.Instance as MapItem;
             if (item != null)
             {
                 pv = item.Item.Value as ParameterValue;
             }
         }
         if (pv == null)
         {
             pv = value as ParameterValue;
         }
         if (pv != null)
         {
             IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             if (edSvc != null)
             {
                 IMathExpression mew = value as IMathExpression;
                 if (mew == null)
                 {
                     mew = pv.MathExpression;
                     if (mew == null)
                     {
                         MathNodeRoot r = new MathNodeRoot();
                         r.Name = pv.Name;
                         mew    = r;
                     }
                 }
                 System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
                 rc.X = curPoint.X;
                 rc.Y = curPoint.Y;
                 IMathEditor dlg = mew.CreateEditor(rc);
                 //
                 MathPropertyGrid pg   = null;
                 Type             t    = edSvc.GetType();
                 PropertyInfo     pif0 = t.GetProperty("OwnerGrid");
                 if (pif0 != null)
                 {
                     object g = pif0.GetValue(edSvc, null);
                     pg = g as MathPropertyGrid;
                 }
                 IMethod imScope = pv.ScopeMethod;
                 if (imScope == null)
                 {
                     imScope = mew.ScopeMethod;
                     if (imScope == null)
                     {
                         if (pg != null)
                         {
                             imScope = pg.ScopeMethod;
                         }
                     }
                 }
                 //
                 dlg.ActionContext = pv.ActionContext;
                 dlg.SetScopeMethod(imScope);
                 dlg.VariableMapTargetType      = typeof(ParameterValue);
                 dlg.MathExpression             = (IMathExpression)mew.Clone();
                 dlg.MathExpression.ScopeMethod = imScope;
                 dlg.MathExpression.EnableUndo  = true;
                 if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
                 {
                     mew = dlg.MathExpression;
                     if (value != pv)
                     {
                         value = mew;
                         pv.SetValue(value);
                     }
                     else
                     {
                         pv.SetValue(mew);
                     }
                     if (pg != null)
                     {
                         pg.OnValueChanged(mew, EventArgs.Empty);
                     }
                 }
             }
         }
     }
     return(value);
 }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             PropertiesWrapper pw = context.Instance as PropertiesWrapper;
             AB_SingleAction   sa = null;
             if (pw != null)
             {
                 sa = pw.Owner as AB_SingleAction;
             }
             ActionClass a = context.Instance as ActionClass;
             if (a == null)
             {
                 if (sa != null)
                 {
                     a = sa.ActionData as ActionClass;
                 }
             }
             ExpressionValue ev = (ExpressionValue)value;
             if (ev == null)
             {
                 ev = new ExpressionValue();
             }
             MathNodeRoot root = ev.GetExpression();
             if (root == null)
             {
                 root = new MathNodeRoot();
                 ev.SetExpression(root);
             }
             if (root.ScopeMethod == null)
             {
                 if (a != null)
                 {
                     if (a.ScopeMethod == null && sa != null)
                     {
                         a.ScopeMethod = sa.Method;
                     }
                     root.ScopeMethod = a.ScopeMethod;
                 }
                 else if (sa != null)
                 {
                     if (sa.ActionData != null && sa.ActionData.ScopeMethod != null)
                     {
                         root.ScopeMethod = sa.ActionData.ScopeMethod;
                     }
                 }
             }
             if (root.ActionContext == null)
             {
                 if (a != null)
                 {
                     root.ActionContext = a;
                 }
                 else if (sa != null)
                 {
                     root.ActionContext = sa;
                 }
             }
             System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
             rc.X = curPoint.X;
             rc.Y = curPoint.Y;
             IMathEditor dlg = root.CreateEditor(rc);
             if (a != null)
             {
                 dlg.ActionContext = a;
             }
             dlg.SetScopeMethod(root.ScopeMethod);
             dlg.VariableMapTargetType      = typeof(ParameterValue);
             dlg.MathExpression             = (IMathExpression)root.Clone();
             dlg.MathExpression.ScopeMethod = root.ScopeMethod;
             dlg.MathExpression.EnableUndo  = true;
             if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
             {
                 root = (MathNodeRoot)dlg.MathExpression;
                 ev   = new ExpressionValue();
                 ev.SetExpression(root);
                 value = ev;
             }
         }
     }
     return(value);
 }