private static void PickOutputParamCmdPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CalculationParamPicker instance = d as CalculationParamPicker;

            if (instance == null)
            {
                return;
            }
            foreach (object child in instance.Children)
            {
                ToggleButton btn = child as ToggleButton;
                if (btn == null)
                {
                    continue;
                }
                if (btn.Name == null)
                {
                    continue;
                }
                if (btn.Name.Contains("OUT"))
                {
                    btn.Command          = instance.PickOutputParamCmd;
                    btn.CommandParameter = btn.Tag;
                    btn.IsChecked        = instance.IsChecked && instance.symbol_current == btn.Tag.ToString();
                }
            }
        }
        private static object CalcUnderConstrCoerceValueCallback(DependencyObject d, object baseValue)
        {
            CalculationParamPicker instance = d as CalculationParamPicker;

            if (instance == null)
            {
                return(baseValue);
            }
            if (instance.CalcUnderConstr != null)
            {
                instance.CalcUnderConstr.PropertyChanged -= instance.calcUC_PropertyChanged;
            }

            return(baseValue);
        }
        private static void CalcNamePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CalculationParamPicker instance = d as CalculationParamPicker;

            if (instance == null)
            {
                return;
            }
            if (instance.CalcUnderConstr == null)
            {
                return;
            }

            instance.CalcUnderConstr.Name = instance.CalcName;
        }
        private static void NrOutputParamsPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CalculationParamPicker instance = d as CalculationParamPicker;

            if (instance == null)
            {
                return;
            }
            if (instance.NrOutputParams < 1 || instance.NrOutputParams > CalculationParamPicker.MAX_NR_OUTPUT_PARAMS)
            {
                return;
            }
            if (instance.CalcUnderConstr == null)
            {
                return;
            }

            List <string> out_symbols_old = instance.CalcUnderConstr.ReturnParams.Keys.ToList();
            List <string> out_symbols_new = new List <string>();

            for (int i = 0; i < instance.NrOutputParams; i++)
            {
                string symbol  = "out0" + (i + 1).ToString();
                bool   success = out_symbols_old.Remove(symbol);
                if (!success)
                {
                    out_symbols_new.Add(symbol);
                }
            }

            if (out_symbols_old.Count > 0)
            {
                foreach (string s in out_symbols_old)
                {
                    instance.CalcUnderConstr.ReturnParams.Remove(s);
                }
            }
            if (out_symbols_new.Count > 0)
            {
                foreach (string s in out_symbols_new)
                {
                    instance.CalcUnderConstr.ReturnParams.Add(s, null);
                }
            }

            instance.UpdateGridStructure();
        }
        private static void IsCheckedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CalculationParamPicker instance = d as CalculationParamPicker;

            if (instance == null)
            {
                return;
            }
            foreach (object child in instance.Children)
            {
                ToggleButton btn = child as ToggleButton;
                if (btn == null)
                {
                    continue;
                }
                btn.IsChecked = instance.IsChecked && instance.symbol_current == btn.Tag.ToString();
            }
        }
        private static void CalcUnderConstrPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CalculationParamPicker instance = d as CalculationParamPicker;

            if (instance == null)
            {
                return;
            }
            if (instance.CalcUnderConstr == null)
            {
                return;
            }

            instance.CalcUnderConstr.PropertyChanged += instance.calcUC_PropertyChanged;

            instance.CalcName         = instance.CalcUnderConstr.Name;
            instance.ExpressionString = instance.CalcUnderConstr.Expression;
            instance.UpdateGridStructure(true);
        }
        private static void ExpressionStringPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CalculationParamPicker instance = d as CalculationParamPicker;

            if (instance == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(instance.ExpressionString))
            {
                return;
            }
            if (instance.CalcUnderConstr == null)
            {
                return;
            }

            var           matches_L           = CalculationParamPicker.LITERAL.Matches(instance.ExpressionString);
            var           matches_F           = CalculationParamPicker.FUNCTION_CALL.Matches(instance.ExpressionString);
            List <string> function_name_comps = new List <string>();

            if (matches_F.Count > 0)
            {
                foreach (Match m in matches_F)
                {
                    string[] comps = m.Value.Split(CalculationParamPicker.FUCNTION_INDICATORS);
                    if (comps != null)
                    {
                        function_name_comps.AddRange(comps);
                    }
                }
            }
            if (matches_L.Count > 0)
            {
                List <string> literal_symbols_old = instance.CalcUnderConstr.InputParams.Keys.ToList();
                List <string> literal_symbols_new = new List <string>();
                foreach (Match m in matches_L)
                {
                    string symbol = m.Value;
                    if (function_name_comps.Contains(symbol))
                    {
                        continue;
                    }

                    bool success = literal_symbols_old.Remove(symbol);
                    if (!success)
                    {
                        literal_symbols_new.Add(symbol);
                    }
                }
                if (literal_symbols_old.Count > 0)
                {
                    foreach (string s in literal_symbols_old)
                    {
                        instance.CalcUnderConstr.InputParams.Remove(s);
                    }
                }
                if (literal_symbols_new.Count > 0)
                {
                    foreach (string s in literal_symbols_new)
                    {
                        instance.CalcUnderConstr.InputParams.Add(s, null);
                    }
                }

                instance.CalcUnderConstr.Expression = instance.ExpressionString;
                instance.UpdateGridStructure();
            }
        }